Sql file to big to upload

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
I have an SQL file that is over 125 meg and I am unable to upload it using phpmyadmin. I was wondering if someone would happen to have a decent php script to include a sql file.

I tried using this code without any luck.

Code:
function parse_mysql_dump($url,$nowhost,$nowdatabase,$nowuser,$nowpass){
    $link = mysql_connect($nowhost, $nowuser, $nowpass);
        if (!$link) {
           die('Not connected : ' . mysql_error());
        }
        
        // make foo the current db
        $db_selected = mysql_select_db($nowdatabase, $link);
        if (!$db_selected) {
           die ('Can\'t use foo : ' . mysql_error());
        }
   $file_content = file($url);
   foreach($file_content as $sql_line){
     if(trim($sql_line) != "" && strpos($sql_line, "--") === false){
     //echo $sql_line . '<br>';
       mysql_query($sql_line);
     }
   }
  }
If anyone has any suggestions please help me out
Edit:
I found this script it works like a dream. Thought many of you would like to see it.

Code:
 <?php
   $sqlFileToExecute = 'ip_info.sql';  //sql file to open 
   $con = mysql_connect($db_host,$db_user,$db_password);
   mysql_select_db($db_name, $con);
   if ($con !== false){
     // Load and explode the sql file
     $f = fopen($sqlFileToExecute,"r+");
     $sqlFile = fread($f,filesize($sqlFileToExecute));
     $sqlArray = explode(';',$sqlFile);
     
     //Process the sql file by statements
     foreach ($sqlArray as $stmt) {
       if (strlen($stmt)>3){
            $result = mysql_query($stmt);
              if (!$result){
                 $sqlErrorCode = mysql_errno();
                 $sqlErrorText = mysql_error();
                 $sqlStmt      = $stmt;
                 break;
              }
           }
      }}
echo '<table> ';
   if ($sqlErrorCode == 0){
      echo "<tr><td>Installation was finished succesfully!</td></tr>";
   } else {
      echo "<tr><td>An error occured during installation!</td></tr>";
      echo "<tr><td>Error code: $sqlErrorCode</td></tr>";
      echo "<tr><td>Error text: $sqlErrorText</td></tr>";
      echo "<tr><td>Statement:<br/> $sqlStmt</td></tr>";
   }
echo '</table>'
?>
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I have an SQL file that is over 125 meg and I am unable to upload it using phpmyadmin. I was wondering if someone would happen to have a decent php script to include a sql file.

If anyone has any suggestions please help me out
Edit:
I found this script it works like a dream. Thought many of you would like to see it.

Did it solve your problem?
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
Well it "worked like a dream." Why is there a file size restriction in the first place?
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
Well it "worked like a dream." Why is there a file size restriction in the first place?

Uploading files = memory hog. While you upload a file, it is put in the memory first (What I've heard), and if there would be like 4 GB RAM (This probably isn't the memory capacity of the server, but eh), and 10 users upload a 100 mb file, they would already use 1 GB RAM, which is not good, and probably makes the server a bit unstable.
 

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
The problem is not just with file size. I have a test server that I could not upload it to either. The other issue is php time out on the script. When you use do an upload most servers only allow 60 - 120 seconds. The file I was trying to upload had over 1,000,000 entries so it would time out before the upload was over.

I used the code above along with splitting the insert into 5 pieces.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
The problem is not just with file size. I have a test server that I could not upload it to either. The other issue is php time out on the script. When you use do an upload most servers only allow 60 - 120 seconds. The file I was trying to upload had over 1,000,000 entries so it would time out before the upload was over.

I used the code above along with splitting the insert into 5 pieces.
Every server implements an upload limit, even the ones that you install on your computer.

My suggestion would have been to split the sql file, but you found a solution!
 
Top