Php xml of MySQL
The PHP download page contains two files: a ZIP file and an installation file. Because we need to add extensions in the ZIP file, both files must be downloaded. The following is a simple step:
1. Use the installation file to install PHP;
2. Decompress iconv. dll and place it in the Windows system folder;
3. Create a directory under the PHP installation directory (C: PHP by default) "extensions ";
4. decompress the PHP_domxml.dll file to this directory;
5. Find the PHP. ini file in the Windows folder and open it in notepad or another text editor. Find "extensions_dir =" in this file, and change its value to the full path of the extension folder set in step 1;
6. Find "; extension = PHP_domxml.dll" and delete the semicolon starting with this line;
7. Restart the Web server.
Then, use the following code in your Web directory to create a PHP page named "test. PHP ". (This code runs properly on Windows 5.0 SP3 running IIS 2000 .)
Reference content is as follows:
Run_ SQL _return_xml ("SELECT * FROM users ");
ClassCMySQLXML {
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 ("");
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 );
}
}