One for the MySQL Class PHP XML
I assume that people use PHP is because of his price: free. MySQL system needed to increase the development of the database features to provide a free database solutions. The shortcomings of these solutions is to set up and manage the complexity of some of the time.
In this article I use the PHP version is PHP 4.3.4 for Win32, can be downloaded from the The PHP Group. MySQL is a version of MySQL 4.0.16 for Win32, can be obtained from MySQL.com. MySQL is very easy to install?? Simple in accordance with its instructions to it. PHP a little bit complicated.
The download page in PHP there are two documents: a ZIP file and an installation file. Because we need to add ZIP file extension, so it should download the two documents. Below is what we have to do after downloading a simple steps:
1. The use of the installation file to install PHP.
2. Decompress iconv.dll, and put it up on the system Windows folder.
3. PHP installation directory create a directory (default is C: PHP) "extensions".
4. Php_domxml.dll extract the files to this directory.
5. In the Windows folder find the php.ini file, and then use Notepad or other text editor to open. Found in the document "extensions_dir =", and then modify the value set for Step 3 of the expansion of the full path of the folder.
6. To find "; extension = php_domxml.dll", delete the semicolon at the beginning of the Bank.
7. Restart the Web server.
And then in your Web directory using the following code to create a PHP page "test.php". (This code is running IIS 5.0 in Windows 2000 sp3 to normal operation.)
$ myxml = new CMySqlXML ( "localhost", "test_user", "password", "test");
echo $ myxml-> run_sql_return_xml ( "SELECT * FROM users");
var $ host;
var $ user;
var $ password;
var $ db;
functionCMySqlXML ($ host, $ user, $ password, $ db) (
$ this-> host = $ host;
$ this-> user = $ user;
$ this-> password = $ password;
$ this-> db = $ db;
functionrun_sql_return_xml ($ sql_string) (
$ connection = mysql_connect ($ this-> host, $ this-> user, $ this-> password,
$ this-> db);
mysql_select_db ($ this-> db);
$ result = mysql_query ($ sql_string);
$ doc = domxml_open_mem ( "<root/>");
while ($ row = mysql_fetch_array ($ result, MYSQL_ASSOC)) (
$ num_fields = mysql_num_fields ($ result);
$ row_element = $ doc-> create_element (mysql_field_table ($ result, 0));
$ doc_root = $ doc-> document_element ();
$ row_element = $ doc_root-> append_child ($ row_element);
for ($ i = 0; $ i <$ num_fields; $ i + +) (
$ field_name = mysql_field_name ($ result, $ i);
$ col_element = $ doc-> create_element ($ field_name);
$ col_element = $ row_element-> append_child ($ col_element);
$ text_node = $ doc-> create_text_node ($ row [$ field_name]);
$ col_element-> append_child ($ text_node);
mysql_free_result ($ result);
mysql_close ($ connection);
return $ doc-> dump_mem (false);
Ask you in this case, there is a MySQL database "test", which has a table "users". In addition, you also need to access data on the test database to create a user. Create database, table, such as MySQL can see the steps of the document.
If you analyze the code, you will understand what I have created a class called CMySqlXML. CMySqlXML constructor to accept four parameters: MySQL host name, a legitimate user name, a password and a database name. Constructor parameter setting using the four categories of host, user, password and db member variable.
Provided such a method is the only run_sql_return_xml (). It to accept a SQL query string parameters. When the implementation of this method, it creates a connection to the MySQL database and select database. Query string was executed, the result stored in the variable $ result. The use of domxml_open_mem () function to create a new DOMDocument object. Then, the code to start the cycle all records of the results of focus. For each record, add a table with the result set rows of the same name DOMDocument document element to element. For each field and then add an element to the line element, the element known as field names. Finally, a text node is added to each field node, the node value of the value of the field.
All rows in the cycle after the release of the results of the code set and close the connection. DOMDocument xml generated from the return function.
In the PHP page you will see the beginning of CMySqlXML object is instantiated, run_sql_return_xml () method is called. This approach has been to return to the return value to the customer. domxml functions in addition to PHP function naming convention other than comply with the DOM specification.
If you need more information on the DOM specification, you can visit the W3C site. Domxml and more information can be found from The PHP Group, where you can download the document in different formats.
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