How to Use php to export and import data to a large database,

Source: Internet
Author: User
Tags chop

How to Use php to export and import data to a large database,
Today, when the network speed is very slow, you can't write or use php to write an exported and imported data to a large database. I think many people often use phpmyadmin to import and export data, however, in many cases where the VM is used, the export is okay, but there is a big problem with the import. I don't think the Webmaster will know much about it here.
Now let's take a look at the php program for importing data from the mysql database.

$ Tname = mysql_query ("select * from table name to be exported ");
If (mysql_num_rows ($ tname) <= 0) exit (); // exit if the data table is empty.
$ Handle = fopen ("Export table.txt", "w"); open a txt file in read/write mode.
$ N_s = mysql_num_fields ($ tname); // obtain the data segment
Fputs ($ handle, $ n_s. ""); write files
For ($ start = 0; $ start
{
$ Msg = mysql_fetch_row ($ tname );
For ($ I = 0; $ I <$ n_s; $ I ++)
{
$ Msg [$ I] = str_replace ("", "& jimmy &", $ msg [$ I]);
$ Msg [$ I] = str_replace ("", "& jimmy &", $ msg [$ I]);
Fputs ($ handle, $ msg [$ I]. "");
}
Fputs ($ handle, "------- php2000 dump data program V1.0 for MySQL --------");
}
Fclose ($ handle );
Print "ostart ";
?>
Now the data export is ready. Now let's take a look at how to import the exported data to the data table. Here we just need to follow the rules we just described.
$ Rate_info = file ("audio table.txt ");
Print $ n_s = chop ($ rate_info [0]);
For ($ start = 1; $ start
{
$ Value = "";
For ($ I = $ start; $ I <($ start + $ n_s-1); $ I ++)
{
$ Tmp = str_replace ("& jimmy &", "", chop ($ rate_info [$ I]);
$ Value. = "'". addslashes ($ tmp )."',";
}
$ Tmp = str_replace ("& jimmy &", "", chop ($ rate_info [$ start + $ n_s-1]);
$ Value. = "'". $ tmp ."'";
$ Query = "insert into $ table values (". $ value .")";
Print mysql_error ();
Mysql_query ($ query );
Print $ start ."";
}
Print "ostart ";
?>
Well, there will be no problem in big data import and export. I hope you can give some help to friends who do not have their own hosts.

Related Article

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.