note 105388 added to function.mysql-field-name

From: Date: Sun, 14 Aug 2011 00:56:09 +0000
Subject: note 105388 added to function.mysql-field-name
Groups: php.notes 
Request: Send a blank email to php-notes+get-182472@lists.php.net to get a copy of this message
simple sql to xml converter works with any sql query and returns the name of the table as the root element "row" as each row element and the names of the columns are your children of row. fully tested. function sqlToXml($host,$user,$pass,$database,$tablename,$query){ $link = mysql_connect($host, $user, $pass) or die("Could not connect: " . mysql_error()); $db = mysql_select_db($database, $link) or die(mysql_error()); $result = mysql_query($query); if(!$result){ die('Invalid query: '.mysql_error()); } $numOfCols = mysql_num_fields($result); $numOfRows = mysql_num_rows($result); $info = mysql_fetch_assoc($result); //send headers header('Content-type: text/xml'); header('Pragma: public'); header('Cache-control: private'); header('Expires: -1'); $xml = '<?xml version="1.0" encoding="utf-8"?>'; $xml.= "<{$tablename}>"; if($numOfRows > 0){ do { $xml.= "<row>"; foreach($info as $column => $value) { $xml.= "<{$column}>{$value}</{$column}>"; } $xml.= "</row>"; } while ($info = mysql_fetch_array($result)); } $xml.= "</{$tablename}>"; mysql_free_result($result); return $xml; } ---- Server IP: 69.147.83.197 Probable Submitter: 78.149.157.153 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-field-name.php Edit -- https://master.php.net/note/edit/105388 Del: integrated -- https://master.php.net/note/delete/105388/integrated Del: useless -- https://master.php.net/note/delete/105388/useless Del: bad code -- https://master.php.net/note/delete/105388/bad+code Del: spam -- https://master.php.net/note/delete/105388/spam Del: non-english -- https://master.php.net/note/delete/105388/non-english Del: in docs -- https://master.php.net/note/delete/105388/in+docs Del: other reasons-- https://master.php.net/note/delete/105388 Reject -- https://master.php.net/note/reject/105388 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#182472) next »