PHP online to import mysql large data program _php instance

Source: Internet
Author: User
Tags chop php online phpmyadmin

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.

Related Article

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.