Using MySQL and PHP to create XML
In this article, I will introduce you to use, such as PHP and mysql open-source tools such as xml to deal with the process. I will be the implementation of a MySQL query and receive data from the query for the xml format as an example to illustrate this. Finally, immerse ourselves in the preparation of the code at the beginning, I will introduce how to write XML documents and to detect system settings.
In order to run the code given in this article, you need to have to run PHP and MySQL, and in order to take full advantage of these examples, you need to know the host name, user name and password. Example of the format of the MySQL database as shown in Figure A. Let us look at how to use PHP to connect to the database.
Establish database connection using PHP
The following PHP script to establish the connection to the database and the implementation of a query:
$ db_name = "xrandomusa_4";
$ connection = mysql_connect ( "MySQL.somewhere.com", "username", "password") or die ( "Could not connect.");
$ table_name = 'pages';
In the MySQL connection is established, you must use the connection to establish the current database. The following code is used to complete this task:
$ db = mysql_select_db ($ dbName, $ link);
Now, with a SQL statement to select all of the $ table_name line:
$ query = "select * from". $ table_name;
If necessary, you can add attributes later. Now, execute the query as follows:
$ result = mysql_query ($ query, $ connection) or die ( "Could not complete database query");
$ num = mysql_num_rows ($ result);
You can get on the PHP.net site to reference all MySQL functions.
And the preparation of the establishment of XML
Now, you should have been done to create a new XML document prepared. There are many methods, but I think the list of A in the method used to meet the vast majority of the purpose.
Now we detail the process. Num variables that you query the data line there or not, its function is mysql_num_rows of MySQL can be measured. Variable $ file contains a pointer, the pointer point to PHP in the file system in search of success to produce a document when results.xml object. If you find result.xml, the PHP files to create your object and the specified file, and the attribute is writable. Now you can print the contents of a variable to create a file (as a result of your directory has been set up to allow PHP to write files, so there is no problem to do so).
Note that from a security perspective, in the actual application development to do so is very foolish. In order to ensure that you can achieve security by involving the concept of this article, you should be open and you want to write full path to the document and ensure that your files are located under the Web root directory.
And then, PHP's mysql_fetch_array function of the variable $ result query into an array, and its cycle of keywords. If pgaeTitle returned in the query field, the return value of each line to the string variable $ _xml write some text.
".="( Operator attention to the XML format is used as a numerical string to splicing) to read $ row. When the end of the cycle, the root XML node to the variable $ _xml print, and all of the variables using PHP's fwrite function to write the document file.xml.
Now, the screen shows a link. Ensure that it links to your XML file path, otherwise you can not see this format XML (the document processing MySQL query using PHP generated).
Php XML Application Articles
- ⑤ browser VML graphics board - view. Php
- A php with XML, XSLT, Mysql combination of the use of the installation of articles
- Second php with XML, XSLT, Mysql combination of the use of code chapter
- Xml file generation lightweight category
- One for the MySQL Class PHP XML
- Using MySQL and PHP to create XML
- PHP and XML-based PDF document generation technology
- The use of XML in PHP
- How to mix XML and PHP?
- A very convenient type of XML! ! Original Oh!
- The use of XML in PHP remote service technology structure (Lower)
- Removed from the SQL data into XMl format
- The use of XML in PHP remote service technology structure (I)
- Notes DOMXML function
- ② Script VML graphics board - VMLgraph. Js, XMLtool.js
- ③ resources VML graphics board - VMLgraph. Xml
Can't Find What You're Looking For?
Rating: Not yet rated