Using PHP and mysql to create XMLThere 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.
|
|
||
|
|||
“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”
Copyright - © 2004 - 2019 - All Rights Reserved.