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> Link to comment https://forums.phpfreaks.com/topic/25992-built-in-function-to-output-mysql-result-set-in-xml-schema/ Share on other sites More sharing options...
marcus Posted November 2, 2006 Share Posted November 2, 2006 You can just use mysql_fetch_array Link to comment https://forums.phpfreaks.com/topic/25992-built-in-function-to-output-mysql-result-set-in-xml-schema/#findComment-118789 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? Link to comment https://forums.phpfreaks.com/topic/25992-built-in-function-to-output-mysql-result-set-in-xml-schema/#findComment-118791 Share on other sites More sharing options...
JustinK101 Posted November 3, 2006 Author Share Posted November 3, 2006 Anybody? Link to comment https://forums.phpfreaks.com/topic/25992-built-in-function-to-output-mysql-result-set-in-xml-schema/#findComment-118854 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. Link to comment https://forums.phpfreaks.com/topic/25992-built-in-function-to-output-mysql-result-set-in-xml-schema/#findComment-118864 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] Link to comment https://forums.phpfreaks.com/topic/25992-built-in-function-to-output-mysql-result-set-in-xml-schema/#findComment-118870 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. Link to comment https://forums.phpfreaks.com/topic/25992-built-in-function-to-output-mysql-result-set-in-xml-schema/#findComment-118882 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] Link to comment https://forums.phpfreaks.com/topic/25992-built-in-function-to-output-mysql-result-set-in-xml-schema/#findComment-118890 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.