<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: From MySQL to XML with PHP</title>
	<atom:link href="http://www.redips.net/php/from-mysql-to-xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redips.net/php/from-mysql-to-xml/</link>
	<description>Techniques and Web Technologies</description>
	<lastBuildDate>Sat, 04 Feb 2012 16:29:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/</generator>
	<item>
		<title>By: geodeta</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-4875</link>
		<dc:creator>geodeta</dc:creator>
		<pubDate>Mon, 02 Jan 2012 21:11:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-4875</guid>
		<description>Thank you for sharing superb informations. Your web-site is so cool. Im impressed by the details that you have on this web site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for extra articles. You, my pal, ROCK! I found just the info I already searched all over the place and just could not come across. What an ideal web-site.</description>
		<content:encoded><![CDATA[<p>Thank you for sharing superb informations. Your web-site is so cool. Im impressed by the details that you have on this web site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for extra articles. You, my pal, ROCK! I found just the info I already searched all over the place and just could not come across. What an ideal web-site.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anuncios clasificados</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-4798</link>
		<dc:creator>Anuncios clasificados</dc:creator>
		<pubDate>Tue, 13 Dec 2011 01:53:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-4798</guid>
		<description>Very cool. thank you very much.. 

George.</description>
		<content:encoded><![CDATA[<p>Very cool. thank you very much.. </p>
<p>George.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dbunic</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-4126</link>
		<dc:creator>dbunic</dc:creator>
		<pubDate>Mon, 27 Jun 2011 14:02:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-4126</guid>
		<description>@Jack - &lt;em&gt;mysql_pconnect&lt;/em&gt; will try to find already opened database connection to avoid overhead regarding connecting and disconnecting to the database. This type of connection will not be closed after PHP script ends. Instead, it will be saved for future use. Please see documentation of &lt;a href=&quot;http://php.net/manual/en/function.mysql-pconnect.php&quot; title=&quot;php.net: Open a persistent connection to a MySQL server&quot; rel=&quot;nofollow&quot;&gt;mysql_pconnect&lt;/a&gt; for a more details.

On the other hand, if you don&#039;t have possibility for Apache and MySQL tuning (like settings of max number of httpd childs or max number of persitent connections to the MySQL server), then &lt;em&gt;mysql_connect&lt;/em&gt; will be just fine.

My only goal was to make sql2xml function more efficient.</description>
		<content:encoded><![CDATA[<p>@Jack - <em>mysql_pconnect</em> will try to find already opened database connection to avoid overhead regarding connecting and disconnecting to the database. This type of connection will not be closed after PHP script ends. Instead, it will be saved for future use. Please see documentation of <a href="http://php.net/manual/en/function.mysql-pconnect.php" title="php.net: Open a persistent connection to a MySQL server" rel="nofollow">mysql_pconnect</a> for a more details.</p>
<p>On the other hand, if you don't have possibility for Apache and MySQL tuning (like settings of max number of httpd childs or max number of persitent connections to the MySQL server), then <em>mysql_connect</em> will be just fine.</p>
<p>My only goal was to make sql2xml function more efficient.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-4122</link>
		<dc:creator>Jack</dc:creator>
		<pubDate>Mon, 27 Jun 2011 03:34:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-4122</guid>
		<description>Hi,

Is there a particular reason you use mysql_pconnect() instead of mysql_connect() in your code?

Thanks</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Is there a particular reason you use mysql_pconnect() instead of mysql_connect() in your code?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dbunic</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-1580</link>
		<dc:creator>dbunic</dc:creator>
		<pubDate>Thu, 26 Nov 2009 09:51:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-1580</guid>
		<description>Bino - If you have LAMP server near to your hands, and &quot;some.sql&quot; is MySQL compatible, then sql2xml() can help you. Procedure can go: 

1) save &quot;some.sql&quot; to the database
2) create XML with PHP function &lt;em&gt;sql2xml()&lt;/em&gt;

I assume that generated XML will not be compatible with PgSQL, but you can apply XSLT on XML to get wanted XML format. Yes, that means to create XSL to transform XML to another XML. Whole procedure seems complicated. I&#039;m just thinking, but did you try to modify &quot;some.sql&quot; like search and replace attribute types for PgSQL syntax - if the goal is to make &quot;some.sql&quot; compatible with PgSQL? Please comment if anything has been left out or is not clear.</description>
		<content:encoded><![CDATA[<p>Bino - If you have LAMP server near to your hands, and "some.sql" is MySQL compatible, then sql2xml() can help you. Procedure can go: </p>
<p>1) save "some.sql" to the database<br />
2) create XML with PHP function <em>sql2xml()</em></p>
<p>I assume that generated XML will not be compatible with PgSQL, but you can apply XSLT on XML to get wanted XML format. Yes, that means to create XSL to transform XML to another XML. Whole procedure seems complicated. I'm just thinking, but did you try to modify "some.sql" like search and replace attribute types for PgSQL syntax - if the goal is to make "some.sql" compatible with PgSQL? Please comment if anything has been left out or is not clear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bino</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-1511</link>
		<dc:creator>bino</dc:creator>
		<pubDate>Fri, 13 Nov 2009 02:27:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-1511</guid>
		<description>Dear Sir.

I have a &quot;some.sql&quot; file in my hand, just like the one you use for creating your &quot;test&quot; database, it&#039;s 2 tables and their record.

So .. How to convert this file to XML format ?
Actualy the final result I need is XML format that compatible with PgSQL

Sincerely
-bino-</description>
		<content:encoded><![CDATA[<p>Dear Sir.</p>
<p>I have a "some.sql" file in my hand, just like the one you use for creating your "test" database, it's 2 tables and their record.</p>
<p>So .. How to convert this file to XML format ?<br />
Actualy the final result I need is XML format that compatible with PgSQL</p>
<p>Sincerely<br />
-bino-</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dbunic</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-175</link>
		<dc:creator>dbunic</dc:creator>
		<pubDate>Wed, 29 Apr 2009 13:38:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-175</guid>
		<description>Yes, sql2xml listed data in a straight line. I made a little modification in PHP code and instead of &lt;em&gt;print&lt;/em&gt;, function uses &lt;em&gt;printf&lt;/em&gt;, so XML output will be nicely indented. Function now has one optional parameter more - starting indent - to add additional spaces before printed line.

I will like to mention that each record (row) fetched from the database will be closed in &lt;ROW&gt;&lt;/ROW&gt; tags. Fetched records should be somehow grouped and nested if you need.

Anyway, XML should be well formed - properly opened and closed tags, to be parse able with XML processors. Indentation is nice to have but not necessary. You can try to save output from sql2xml to the XML file (don&#039;t forget xml suffix) and open with FF or IE. Browser should recognize XML document type and display it indented - no matter if original XML is listed in straight line or not.

Please comment if anything has been left out or is not clear.
</description>
		<content:encoded><![CDATA[<p>Yes, sql2xml listed data in a straight line. I made a little modification in PHP code and instead of <em>print</em>, function uses <em>printf</em>, so XML output will be nicely indented. Function now has one optional parameter more - starting indent - to add additional spaces before printed line.</p>
<p>I will like to mention that each record (row) fetched from the database will be closed in &lt;ROW&gt;&lt;/ROW&gt; tags. Fetched records should be somehow grouped and nested if you need.</p>
<p>Anyway, XML should be well formed - properly opened and closed tags, to be parse able with XML processors. Indentation is nice to have but not necessary. You can try to save output from sql2xml to the XML file (don't forget xml suffix) and open with FF or IE. Browser should recognize XML document type and display it indented - no matter if original XML is listed in straight line or not.</p>
<p>Please comment if anything has been left out or is not clear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jasen Burkett</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-174</link>
		<dc:creator>Jasen Burkett</dc:creator>
		<pubDate>Tue, 28 Apr 2009 23:00:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-174</guid>
		<description>How do I get it to structure the xml file like so ...

&lt;gname&gt;Cars&lt;/gname&gt;
&#160;&#160;&lt;imgName&gt;Image 1&lt;/imgName&gt;
&#160;&#160;&#160;&#160;&lt;caption&gt;Image 1 Caption&lt;/caption&gt;
&lt;gname&gt;Jasen and Jenn&lt;/gname&gt;

basically..your code works, I mean obviously..
but it does not format the xml into the above format.
it just lists it out in a straight line.

so the code is doing what it needs to do, but its not
structuring it.

am I missing something somewhere?

thanks
Jasen</description>
		<content:encoded><![CDATA[<p>How do I get it to structure the xml file like so ...</p>
<p>&lt;gname&gt;Cars&lt;/gname&gt;<br />
&nbsp;&nbsp;&lt;imgName&gt;Image 1&lt;/imgName&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;caption&gt;Image 1 Caption&lt;/caption&gt;<br />
&lt;gname&gt;Jasen and Jenn&lt;/gname&gt;</p>
<p>basically..your code works, I mean obviously..<br />
but it does not format the xml into the above format.<br />
it just lists it out in a straight line.</p>
<p>so the code is doing what it needs to do, but its not<br />
structuring it.</p>
<p>am I missing something somewhere?</p>
<p>thanks<br />
Jasen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dbunic</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-173</link>
		<dc:creator>dbunic</dc:creator>
		<pubDate>Tue, 28 Apr 2009 10:48:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-173</guid>
		<description>Jasen,
as I can read from your comment, you have MySQL table &quot;photogallery&quot; with attributes &lt;em&gt;gname&lt;/em&gt;, &lt;em&gt;title&lt;/em&gt; and &lt;em&gt;image&lt;/em&gt; (&lt;em&gt;gname&lt;/em&gt; is gallery name). To produce XML hierarchy with sql2xml function from this post, you will have to create small PHP file:

&lt;? include(&#039;sql2xml.php&#039;) ?&gt;  
&lt;DOCUMENT&gt;
&lt;? sql2xml(&#039;select gname, image from photogallery order by gname, title&#039;, &#039;1&#039;) ?&gt;  
&lt;/DOCUMENT&gt;

Optional parameter &#039;1&#039; means to have first column (&lt;em&gt;gname&lt;/em&gt;) in level 1 while other columns from the select will be placed to the lower level. Please download &lt;a href=&quot;/my/tar/redips1.tar.gz&quot; title=&quot;XML and XSL examples&quot; rel=&quot;nofollow&quot;&gt;redips1.tar.gz&lt;/a&gt; where you can find prepared examples and short readme.txt file. You will have to set MySQL username and password in sql2xml.php file (line 13) and edit test.php file (just replace select statement).</description>
		<content:encoded><![CDATA[<p>Jasen,<br />
as I can read from your comment, you have MySQL table "photogallery" with attributes <em>gname</em>, <em>title</em> and <em>image</em> (<em>gname</em> is gallery name). To produce XML hierarchy with sql2xml function from this post, you will have to create small PHP file:</p>
<p>< ? include('sql2xml.php') ?><br />
&lt;DOCUMENT&gt;<br />
< ? sql2xml('select gname, image from photogallery order by gname, title', '1') ?><br />
&lt;/DOCUMENT&gt;</p>
<p>Optional parameter '1' means to have first column (<em>gname</em>) in level 1 while other columns from the select will be placed to the lower level. Please download <a href="/my/tar/redips1.tar.gz" title="XML and XSL examples" rel="nofollow">redips1.tar.gz</a> where you can find prepared examples and short readme.txt file. You will have to set MySQL username and password in sql2xml.php file (line 13) and edit test.php file (just replace select statement).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jasen</title>
		<link>http://www.redips.net/php/from-mysql-to-xml/comment-page-1/#comment-171</link>
		<dc:creator>Jasen</dc:creator>
		<pubDate>Fri, 24 Apr 2009 02:11:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=34#comment-171</guid>
		<description>I have two tables.  one is holding the gallery name
and the second table is holding the gallery name with the image name and caption.

I need to be able to output the xml script in the exact same way as you have yours here.
but when I typed in all your info, and followed all the tutorial on this page, nothing happened.

here is my code that I have now....

&lt;?php
require(&quot;config.php&quot;);

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace(&#039;&#039;,&#039;&gt;&#039;,$xmlStr); 
$xmlStr=str_replace(&#039;&quot;&#039;,&#039;&quot;&#039;,$xmlStr); 
$xmlStr=str_replace(&quot;&#039;&quot;,&#039;&#039;&#039;,$xmlStr); 
$xmlStr=str_replace(&quot;&amp;&quot;,&#039;&amp;&#039;,$xmlStr); 
return $xmlStr; 
} 

// Opens a connection to a MySQL server
$connection=mysql_connect (&#039;localhost&#039;, $username, $password);
if (!$connection) {
  die(&#039;Not connected : &#039; . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die (&#039;Can\&#039;t use db : &#039; . mysql_error());
}

// Select all the rows in the markers table
$query = &quot;SELECT image FROM photogallery WHERE image ORDER BY title DESC&quot;;
$result = mysql_query($query);
if (!$result) {
  die(&#039;Invalid query: &#039; . mysql_error());
}

header(&quot;Content-type: text/xml&quot;);

// Start XML file, echo parent node
echo &#039;&#039;;
echo &#039;&#039;;
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo &#039;&#039;;
  echo &#039;&#039; . parseToXML($row[&#039;title&#039;]) . &#039;&#039;;
  echo &#039;http://www.cbchangar.com/uploads/images/&#039; . $row[&#039;image&#039;] . &#039;&#039;;
  echo &#039;&#039; . $row[&#039;description&#039;] . &#039;&#039;;
  echo &#039;&#039;;
}
echo &#039;&#039;;
// End XML file
?&gt;


how would I get it to output the xml like this

  

1  
Gallery 1    
   

  
2  
Gallery 2    
   

  

basically I need to have the php script output the mysql data, but it needs to list all images associated with the gallery name.  so when the client updates the photo gallery, when they create a new gallery they give it a name... that name is stored into the database by gname.  so the xml file would list say gallery 1 then list all the images that are tagged or associated with gallery 1, then it would close that gname tag and then go to gname again which would say gallery 2, and so forth.

any help would be greatly appreciated</description>
		<content:encoded><![CDATA[<p>I have two tables.  one is holding the gallery name<br />
and the second table is holding the gallery name with the image name and caption.</p>
<p>I need to be able to output the xml script in the exact same way as you have yours here.<br />
but when I typed in all your info, and followed all the tutorial on this page, nothing happened.</p>
<p>here is my code that I have now....</p>
<p>&lt;?php<br />
require("config.php");</p>
<p>function parseToXML($htmlStr)<br />
{<br />
$xmlStr=str_replace('','&gt;',$xmlStr);<br />
$xmlStr=str_replace('"','&quot;',$xmlStr);<br />
$xmlStr=str_replace("'",'&#39;',$xmlStr);<br />
$xmlStr=str_replace("&amp;",'&amp;',$xmlStr);<br />
return $xmlStr;<br />
} </p>
<p>// Opens a connection to a MySQL server<br />
$connection=mysql_connect ('localhost', $username, $password);<br />
if (!$connection) {<br />
  die('Not connected : ' . mysql_error());<br />
}</p>
<p>// Set the active MySQL database<br />
$db_selected = mysql_select_db($database, $connection);<br />
if (!$db_selected) {<br />
  die ('Can\'t use db : ' . mysql_error());<br />
}</p>
<p>// Select all the rows in the markers table<br />
$query = "SELECT image FROM photogallery WHERE image ORDER BY title DESC";<br />
$result = mysql_query($query);<br />
if (!$result) {<br />
  die('Invalid query: ' . mysql_error());<br />
}</p>
<p>header("Content-type: text/xml");</p>
<p>// Start XML file, echo parent node<br />
echo '';<br />
echo '';<br />
// Iterate through the rows, printing XML nodes for each<br />
while ($row = @mysql_fetch_assoc($result)){<br />
  // ADD TO XML DOCUMENT NODE<br />
  echo '';<br />
  echo '' . parseToXML($row['title']) . '';<br />
  echo '<a href="http://www.cbchangar.com/uploads/images/" rel="nofollow">http://www.cbchangar.com/uploads/images/</a>' . $row['image'] . '';<br />
  echo '' . $row['description'] . '';<br />
  echo '';<br />
}<br />
echo '';<br />
// End XML file<br />
?&gt;</p>
<p>how would I get it to output the xml like this</p>
<p>1<br />
Gallery 1    </p>
<p>2<br />
Gallery 2    </p>
<p>basically I need to have the php script output the mysql data, but it needs to list all images associated with the gallery name.  so when the client updates the photo gallery, when they create a new gallery they give it a name... that name is stored into the database by gname.  so the xml file would list say gallery 1 then list all the images that are tagged or associated with gallery 1, then it would close that gname tag and then go to gname again which would say gallery 2, and so forth.</p>
<p>any help would be greatly appreciated</p>
]]></content:encoded>
	</item>
</channel>
</rss>

