echo "
";
//print_r($data);
$data_new=array();
$tmp=array();
foreach ($data as $line) {$line=trim($line);
if(strlen($line)==0){
continue;
}
if(substr($line,2)=='--'){
continue;
}
if(substr($line,2)=='/*'){
continue;
}
$tmp[]=$line;
if(substr($line,-1)==';'){
$query=implode('',$tmp);
$tmp=array();
$data_new[]=$query;
}
}$MysqLi=new MysqLi('localhost','root','test');
if($MysqLi->connect_errno){
exit('数据库连接失败!');
}
$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: 0MysqL>ALTER TABLE tbl2 ENABLE KEYS;
Query OK,0 rows affected (44.55 sec)*/
适用情况:PHPmyadmin导出的sql文件过大,无法导入到线上PHPmyadmin中
以上所述就是本文的全部内容了,希望大家能够喜欢。