php to import mysql large data program online
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the same as the |
<?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) = = '--') {Conti Nue } 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 ENA BLE 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$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.