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.