How to import a large database with PHP export

Source: Internet
Author: User
Tags chop table name

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.

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.