<? 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) */ |