Implementation of data storage and backup using XML (2)

Source: Internet
Author: User
Tags sql server sql
xml| Backup | data

$fields =mysql_list_fields ("Embed", $table, $con);
$j = 0;
$num _fields=mysql_field_name ($fields, $j);
echo $num _fields;
while ($j <mysql_num_fields ($fields)) {
$num _fields=mysql_field_name ($fields, $j);
$filestr. = "<" $num _fields. " > ";
$filestr. = $row [$j];
$filestr. = "</". $num _fields. " > ";
$j + +;}
$filestr. = "</". $table. " > ";
}
$filestr. = "</". $table. " S> ";
Echo $filestr;
Here is the file manipulation code
$filename = $table. ". XML ";
$FP =fopen ("$filename", "w");
Fwrite ($fp, $FILESTR);
Fclose ($FP);
Echo "Datasheet". $table. " Backup has been successful! ";? >
</body>



By using the above files, you can perform a backup of the tables selected in the database.

The above mainly introduces two ways of using XML Backup database operation method, in fact, is not complex, through XML, we can back up a variety of databases, of course, can also be related to the method of the backup of the XML document back to the database, here is not described in detail.

2. Exchanging data between different databases

Another feature of XML is that it can be used to exchange data in different databases, as described above, we can export some type of database file from one system to another, and then import the data into other databases in another system. XML makes the exchange of data between different databases across platforms more convenient.

What if we want to send data from Oracle to SQL Server? If we don't use XML, everything will be very complex, and using XML to encapsulate the data in Oqacle into an XML file can be read by another database system, such as SQL Server.

3. Display data

Because XML itself focuses on content, it does not work for display data itself, and XML data is displayed in a very different way, through CSS (cascading Style Sheet), XSL (extensible Stylesheet Language) or data Binding, and many other ways to display it.

Since XML is separate from data and style, we can arbitrarily change the display format of the data in our own imagination without doing anything with the XML document, which makes the data more flexible and free.

Because the XML display is more complex to describe, this is not covered in detail.

4, itself as data storage
In fact, we have just introduced the use of XML to back up the database, forget to introduce, XML itself can be used to store data, in fact, in the following cases, using XML to store data is very good.

Information data is more complex:
In fact, a complex data does not necessarily be very good through the database to display, but it can be very good to use XML to display. For example, the record of a book, usually has the name and the author, if the author only one, can be very convenient to use the database to display, but if a book has two, three or more authors, this time, XML can easily solve
Separate fields are complex and large
Also for the record of the book mentioned just now, if we want to put each chapter of the book in the database is not a good store, the database of each field is long, will waste a lot of space.
Data types and search speed are not important
Of course, there are some problems with XML, although the search for XML has been greatly optimized, but the speed is still very slow. And all of the data in XML is stored through strings, so it's not very appropriate to use XML to store data for data type requirements that are very important.
Database is small, but can be extended
In addition, because of the good scalability of XML, XML is also useful for small, data storage that needs to be constantly modified.

In addition, if your system has multiple servers and database systems, you can use XML, and XML can easily transfer data from Linux to the Windows platform. In addition, consider the choice of XML as a database for long-term storage.

When to store data without XML
By using the previous data storage comparison with XML, we should also know when it is not appropriate to use XML for data storage, if we have a high demand for database queries, XML is not appropriate, and if the data type of the stored data is important, XML is not appropriate.

Any technology has drawbacks, XML is not appropriate, but it will provoke all the data processing and transmission of the responsibility, which is the birth of XML is an important reason. In the future, we will see the existence of XML in more products and applications, especially when it comes to data transfer.

Zhou
Lenovo Group embedded Application Research and Development Department software engineer, the main research interest is the application of XML in the technology Next generation Web service. You can contact him through zhoush@legend.com.



Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.