note 73817 added to ref.simplexml

From: Date: Sun, 11 Mar 2007 21:46:17 +0000
Subject: note 73817 added to ref.simplexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-124352@lists.php.net to get a copy of this message
Sometimes it's nice to mix up data storage types. This is a very simple SQL to XML converter. Feed it a SQL query and it outputs the result in XML. The first paramater should be a mysql_query result (optional)The second is the xml name for each row (i.e the second depth of XML) (optional)The third is the name of the XML document, the root name <?php $result=mysql_query("SELECT * FROM users"); sql_to_xml($result,"users","members"); function sql_to_xml($mysql_result,$row_name="row",$doc_name="root") { $xml= new SimpleXMLElement("<$doc_name></$doc_name>"); while($line=mysql_fetch_assoc($mysql_result)) { $row=$xml->addChild($row_name); foreach($line as $column => $value) { $row->$column="$value"; } } return $xml->asXML(); } ?> ---- Server IP: 87.124.64.96 Probable Submitter: 82.43.58.81 ---- Manual Page -- http://www.php.net/manual/en/ref.simplexml.php Edit -- https://master.php.net/note/edit/73817 Del: integrated -- https://master.php.net/note/delete/73817/integrated Del: useless -- https://master.php.net/note/delete/73817/useless Del: bad code -- https://master.php.net/note/delete/73817/bad+code Del: spam -- https://master.php.net/note/delete/73817/spam Del: non-english -- https://master.php.net/note/delete/73817/non-english Del: in docs -- https://master.php.net/note/delete/73817/in+docs Del: other reasons-- https://master.php.net/note/delete/73817 Reject -- https://master.php.net/note/reject/73817 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124352) next »