JustinK101 Posted November 2, 2006 Share Posted November 2, 2006 Is there a built in php function which converts a mysql result object into strucutred and formatted XML? I know MSSQL has this option built into the language, but I dont think mysql does.Example:$sql = "SELECT first_name, last_name FROM logins ORDER BY last_name";$result = mysql_query($sql);Becomes<resultSet> <logins> <first_name>Bob</first_name> <last_name>Apple</last_name> </logins> <logins> <first_name>James</first_name> <last_name>Bee</last_name> </logins></resultSet> Quote Link to comment Share on other sites More sharing options...
marcus Posted November 2, 2006 Share Posted November 2, 2006 You can just use mysql_fetch_array Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted November 2, 2006 Author Share Posted November 2, 2006 Really how so? mysql_fetch_array doesnt return formatted xml does it? Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted November 3, 2006 Author Share Posted November 3, 2006 Anybody? Quote Link to comment Share on other sites More sharing options...
trq Posted November 3, 2006 Share Posted November 3, 2006 there is no builtin to do this. You'd need to roll your own, or just create the xml manually. Quote Link to comment Share on other sites More sharing options...
rab Posted November 3, 2006 Share Posted November 3, 2006 [code]$sql = "SELECT first_name, last_name FROM logins ORDER BY last_name";$result = mysql_query($sql);if( !$result ) { die( "Query Failed...." );}while( $people = mysql_fetch_array($result) ) { print "<first_name>".$people['first_name']."</first_name>"; print "<last_name>".$people['last_name']."</last_name>";}[/code] Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted November 3, 2006 Author Share Posted November 3, 2006 HUmm looking for a standarized function, which doesnt know ahead of time how many rows/columns, and the column names. I think I may be able to write something. I will respond when I get something going. Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted November 3, 2006 Author Share Posted November 3, 2006 Ehhhhhhhhhh, I wrote this real quick, not sure if it will work though, anybody want to test for me?[code]function mysql_to_xml($resultObj) { echo '<results>'; while($row = mysql_fetch_array($resultObj)) { echo '<' . mysql_tablename($resultObj, 0) . '>'; for($i = 0; $i < mysql_num_rows($resultObj); $i++) { echo '<' . mysql_field_name($resultObj, $i) . '>' . $row[$i] . '</' . mysql_field_name($resultObj, $i) . '>'; } echo '</' . mysql_tablename($resultObj, 0) . '>'; } echo '</results>'; }[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.