+ Reply to Thread
Results 1 to 6 of 6

Thread: Sql file to big to upload

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Sql file to big to upload

    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 by driveflexfuel; 08-20-2009 at 04:41 PM. Reason: Automerged Doublepost

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Sql file to big to upload

    Quote Originally Posted by driveflexfuel View Post
    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?
    Nothing is always absolutely so.

  3. #3
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Sql file to big to upload

    Well it "worked like a dream." Why is there a file size restriction in the first place?

  4. #4
    galaxyAbstractor's Avatar
    galaxyAbstractor is offline Community Advocate galaxyAbstractor is on a distinguished road
    Join Date
    Oct 2007
    Location
    Land of Null and Insanity
    Posts
    5,495

    Re: Sql file to big to upload

    Quote Originally Posted by Twinkie View Post
    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.

  5. #5
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Re: Sql file to big to upload

    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.

  6. #6
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: Sql file to big to upload

    Quote Originally Posted by driveflexfuel View Post
    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!
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

+ Reply to Thread

Similar Threads

  1. file upload script
    By nightscream in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 01-11-2011, 05:04 PM
  2. 500 Internal Server Error
    By cgrim29588 in forum Free Hosting
    Replies: 2
    Last Post: 03-17-2009, 02:54 PM
  3. Perl Help
    By cgrim29588 in forum Free Hosting
    Replies: 1
    Last Post: 02-16-2009, 02:06 PM
  4. configuring php on localhost
    By ufclan in forum Scripts & 3rd Party Apps
    Replies: 15
    Last Post: 01-22-2008, 08:34 AM
  5. [PHP] Creating a File Upload Script
    By o0slowpaul0o in forum Tutorials
    Replies: 17
    Last Post: 10-05-2005, 01:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers