Import of big database
Posted by: fritz müller
Date: December 06, 2012 03:00PM

if the import function of phpmyadmin fails, my script imports very big database dumps. Just use the script.

Importscript to import Big SQL scripts
It handles very Big SQL scripts.


1. Upload this script to your server. Change the SQL Properties before

2. Upload the SQL file to the same Folder (Best with FTP)

3. Call the Script with the SQL Filename as GET Parameter (Example:

Copyright by Lucius Bachmann
function db()//Function to Connect to Database
$MySQL_Host="Your-MySQL Host";
$MySQL_User="Your Mysql User";
$MySQL_Passw="Your Mysql Password";
$db="Your DB Name";

echo mysql_error($dblk);

$dblk=db();//Database connect
session_start();//start session
$maxtime=ini_get("max_execution_time");// get max execution time

if(isset($_SESSION['pointer'])){//If the skript was called by itself, set the variables as they where before
$pointer = $_SESSION['pointer'];
$sql = $_SESSION['sql'];
$counter = $_SESSION['counter'];
$fehler = $_SESSION['fehler'];
$Filename= $_SESSION['filename'];
$FileHandler = fopen($Filename, 'r') or die("can't open file");
fseek($FileHandler, $pointer);//Jump to the place the pointer was before
else{//If its the first call, initialize the Variables

$Filename = $_GET['filename'];


$FileHandler = fopen($Filename, 'r') or die("can't open file");

while(time()-$starttime+5 < $maxtime){// As long as you have Execution Time, And to avoid maximum execution timeout
$line=fgets($FileHandler);//Read line
if($line === false){//If End Of file, exit
while(!(strpos($line, "--")===false)){//If a comment line, get next line

$pointer=ftell($FileHandler);//get the offset of the filecursor
$string=substr($line,0, strlen($line)-1);//read the line into a string
$sql.=$string;//append to sql order
$lastletter=substr($line, strlen($line)-2, strlen($line)-1);// get the last letter of the line
if(!(strpos($lastletter, ";")===false)){//If the last letter was a semicolon,

if(!mysql_query($sql)){//Mysql query
$fehler.="SQL Fehler: $sql <br>";// Fehler Save
$counter++;// count the orders


if(isset($EndofFile)){//If the sql import is finished, show stats
SQL Befehle ausgeführt: $counter <br>
Time Used: $timeUsed seconds <br>
Fehler: $fehler <br>
else{//save the variables in the session


echo "<script>window.location='".$_SERVER['PHP_SELF']."';</script>";//and call the script itself


Options: ReplyQuote

Written By
Import of big database
December 06, 2012 03:00PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.