How to import a large database with PHP export
Today's speed is very slow no way to write with PHP to write an export import into a large database, I think many people often use phpMyAdmin for data import and export, but in a lot of use of virtual host, the export is no problem, but import there are a lot of problems, I think here I do not say a lot of webmaster will know.
All right, let's take a look at the PHP data import program in the MySQL database.
$tname = mysql_query ("SELECT * from table name to export");
if (mysql_num_rows ($tname) <= 0) exit (); If the datasheet is empty, just exit the understanding
$handle = fopen ("$table. txt", "w"); We open a TXT file in read and write mode.
$n _s = Mysql_num_fields ($tname); The segment that gets the data
Fputs ($handle, $n _s. " "); Write a file
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";
?>
Okay, now that data export is written, now let's see how we can import the exported data we just wrote into the datasheet, and just follow the rules we just ostart.
$rate _info = File ("$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";
?>
Okay, big data import and export there is no problem, I hope you do not have their own host friend some help.