Create xml_php tutorials with MySQL and PHP

Source: Internet
Author: User
XML (which is becoming more and more standardized) appears as a standard for data exchange. Both Java and. NET support XML internally (standardization is getting closer), but developers on other platforms don't have to worry about being abandoned by the technology. PHP, which is now the mainstream development language, is a popular scripting environment that supports XML, which is getting closer to standardization.

In this article, I'll show you the process of using open source tools such as PHP (which is now the mainstream development language) and MySQL (the best combination of PHP collocation) to handle XML (standardization is getting closer). I'm going to run a MySQL (and the best combination of PHP) queries and explain the data format from the query to XML (standardization is getting closer) as an example. Finally, before I start burying my code, I'll show you how to write XML (normalization getting closer) to the file and detect system settings.

In order to run the code given in this article, you need to be able to run PHP (as the current mainstream development language) and MySQL (the best combination with PHP), and to take advantage of these examples, you need to know the hostname, username, and password. Example of MySQL (and the best combination of PHP) database is shown in format a. Let's see how to connect to the database using PHP, which is now the mainstream development language.

Figure A



Build database connections with PHP (as the current mainstream development language)

The following PHP (as the current mainstream development language) script establishes a connection to the database and executes a query:

$db _name = "Xrandomusa_4";
$connection = MySQL (best combination with PHP) _connect ("MySQL (best combination with PHP). somewhere.com", "username", "password") or Die ("Could Not connect. ");
$table _name = pages;

Query MySQL (and the best combination of PHP collocation)

After the connection is established for MySQL (and the best combination of PHP collocation), you must use that connection to establish the current database. The following code is used to accomplish this task:

$db = MySQL (the best combination of PHP collocation) _select_db ($dbName, $link);

Now, use an SQL statement to select all the rows in the $table _name :
$query = "SELECT * from". $table _name;

If necessary, you can then add properties. Now execute the query as follows:
$result = MySQL (the best combination with PHP) _query ($query, $connection) or Die ("Could not complete database query");
$num = MySQL (the best combination of PHP collocation) _num_rows ($result);

You can get a reference to all of MySQL (and the best combination of PHP) functions using PHP (as the current mainstream development language). NET website.

Build and write XML (standardization getting closer)

Now you should be ready to set up a new XML (standardized getting closer) document. There are a number of ways to do this, but I think the method used in listing a can satisfy most purposes.

We will now describe this process in detail. The variable num Indicates whether the row of data you are querying appears or not, and it is measurable for the MySQL (and PHP Best Mix) _num_rows function for MySQL (and the best combination of PHP collocation). The variable $file contains a pointer to the file object that PHP (as the current mainstream development language) successfully searches for when results.xml (normalization is getting closer) in the file system. If you find Result.xml (standardization is getting closer), create your PHP (the current mainstream development language) file object and specify the file, and its properties are writable. Now you can print the contents of a variable to the created file (since your directory has been set to allow PHP to write files for the current mainstream development language), so this is no problem.

Note that, from a security standpoint, it is foolish to do so in real-world application development. To ensure that you can safely implement the concepts covered in this article, you should provide a full path for the file that you want to open and write, and make sure that the file is located under your Web root directory.

Then, the MySQL (the best combination of PHP collocation) for PHP (which is now the mainstream development language) _fetch_array function converts the query variable $result into an array and loops through its keywords. If Pgaetitle is in the column returned by the query, the return value for each row is written to the string variable $_xml (normalization is getting closer) to some text.

Note that the operator ". =" (which is used to stitch the XML (normalized, more and more closely formatted) string as a numeric value) reads $row . As the loop ends, the root XML (normalization is getting closer) is printed to the variable $_xml (normalization is getting closer) , and all variables are written in PHP (as the current mainstream development language) Fwrite function File.xml ( Standardization is getting closer) among the documents.

A link is now displayed on the screen. Make sure that the link points to the path to your XML (normalized closer) file, or you won't see this formatted XML (normalization is getting closer) (the file is generated using PHP (as the current mainstream development language) to handle MySQL (and the best combination of PHP) queries.

http://www.bkjia.com/PHPjc/508754.html www.bkjia.com true http://www.bkjia.com/PHPjc/508754.html techarticle XML (which is becoming more and more standardized) appears as a standard for data exchange. Both Java and. NET support XML internally (standardization is getting closer), but developers on other platforms don't have to worry about ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.