PHP online import mysql large data program
<?php header ("Content-type:text/html;charset=utf-8");
Error_reporting (E_all);
Set_time_limit (0);
$file = './test.sql ';
$data =file ($file);
echo "<pre>";
Print_r ($data);
$data _new=array ();
$tmp =array ();
foreach ($data as $line) {$line =trim ($line);
if (strlen ($line) ==0) {continue;
} if (substr ($line, 0,2) = = '--') {continue;
} if (substr ($line, 0,2) = = '/* ') {continue;
} $tmp []= $line; if (substr ($line,-1) = = '; ')
{$query =implode (", $tmp);
$tmp =array ();
$data _new[]= $query;
} $mysqli =new mysqli (' localhost ', ' root ', ' root ', ' test '); if ($mysqli->connect_errno) {exit (' Database connection failed!
');
} $mysqli->query ("Set names UTF8");
$error =array ();
foreach ($data _new as $sql) {$mysqli->query ($sql);
$r = $mysqli->error;
if ($r) $error []= $r;
} print_r ($r);
/* Mysql>alter TABLE tbl2 DISABLE KEYS;
Query OK, 0 rows Affected (0.00 sec) Mysql>insert into tbl2 SELECT * from TBL1; Query OK, 2000000 row Affected (36.30 sec) records:2000000 Duplicates:0 warnings:0 mysql>alter TABLE tbl2 ENABLE KEYS;
Query OK, 0 rows affected (44.55 sec) * *
Application: phpMyAdmin The exported SQL file is too large to be imported into the online phpMyAdmin
Upload the program and SQL file into space, and then delete it after use.
Share a method of other netizens, small partners can also refer to the
$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";
The above mentioned is the entire content of this article, I hope you can enjoy.