Using PHP and mysql to create XML

There might be scenario where you need to create XML files from the data available in a mysql database. You can use the PHP functions to connect to the database and build the XML file from the scratch or use the DOM functions to create the XML file. Either way you can achieve that.


_______________________________________________


You can use the mysql_connect function to connect to your mysql database. This function takes the server in which the database is hosted, the username and the password as the arguments. The mysql_select_db function is used to select the database in which you are going to work and use the mysql_query to get the result of the query on a particular table.

The mysql_query function takes the query and the connection variable as the arguments. The result of the query is assigned to an variable and the number of rows in this variable is checked to see if there are any records out of the query.

If there are any rows present, then you can build the XML file using a while loop. The simplest way is to concatenate variable to the different elements within the loop. If needed, you can write the result in a file using the fopen, fwrite, and fclose functions.





_______________________________________________

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________







 

 

FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!

Visit XML Training Material Guide Homepage

 

 

Copyright - © 2004 - 2017 - All Rights Reserved.