• PHP Help PHP Coding
  • Trying to restore a MySQL database from an SQL dump: Problems with file inclusion.

I just moved to a new web host and they refuse to give me SSH access despite what their website's plan page shows I should have (I'm hating shared hosting. I miss my VPS), so I've decided to try restoring my MySQL database with PHP. After connecting to the database, my script basically runs mysql_query(include($database)) as seen here:

<?php

$host  = "xxxxxxxx";
$user  = "xxxxxxxx";
$pass  = "xxxxxxxx";
$dbase = "xxxxxxxx";

mysql_connect($host,$user,$pass);
mysql_select_db($dbase) or DIE("Unable to select specified database!");

echo "Restoring database. Please wait....";

$query = include("vbulletin-xxxxxxxx.sql");
mysql_query($query);

echo "Congratulations! Restoration finished!";

mysql_close();
?>

When I try to execute this, I get problems with the file inclusion:

Warning: Unexpected character in input: '' (ASCII=21) state=1 in /xxx/xxx/xxx/xxx/xxx/vbulletin-xxxxxxxx.sql on line 277

Warning: Unexpected character in input: '' (ASCII=19) state=1 in /xxx/xxx/xxx/xxx/xxx/vbulletin-xxxxxxxx.sql on line 277

Parse error: syntax error, unexpected T_VARIABLE in /xxx/xxx/xxx/xxx/xxx/vbulletin-xxxxxxxx.sql on line 277

I'm fairly sure it's getting upset over a GIF image which is stored in the database (vBulletin stores attachments this way), but my forum has several attachments, and I can't remove them all.

Any suggestions as to how I can restore this database?

    Hi!
    I think you are missing something. What is this?

    $query = include("vbulletin-xxxxxxxx.sql");
    

    Read http://no2.php.net/manual/en/function.include.php

    Im not sure what you want, but trying to put an include into a variable has nothing to do with shared hosts, your database or GIF images.

    If you want to put an include into variable do like this:

    ob_start();
    include('theFile');
    $output = ob_get_contents();
    ob_end_clean();
    

    Read about output control

      gammaster wrote:

      Hi!
      I think you are missing something. What is this?

      $query = include("vbulletin-xxxxxxxx.sql");
      

      Read http://no2.php.net/manual/en/function.include.php

      Im not sure what you want, but trying to put an include into a variable has nothing to do with shared hosts, your database or GIF images.

      If you want to put an include into variable do like this:

      ob_start();
      include('theFile');
      $output = ob_get_contents();
      ob_end_clean();
      

      Read about output control

      You're right. Thanks for pointing this out. I suppose I was using include() incorrectly, and this wouldn't have worked properly.

      Anyway, PHP still has problem with the include function, regarding the GIF images in the database. It just doesn't like the character set being used, and goes ape when it comes to the line containing the image.

      I submitted a support ticket to my new host and they offered to restore the database themselves manually, so I guess I won't have to deal with this obscure method of database restoration anyway.

      Thanks for the help, gammaster.

        I have the same problem with my host , Can you please give me a copy of your script to restore sql backup (80mb) ?

          4 days later

          You should use the mysql client program to restore it.

          If they won't give you shell access, use mysql client remotely. It's slow, but it works.

          include() is definitely not the right way to get a file into PHP. Also at 80Mb, it's probably too big to work like that, PHP may timeout etc.

          Mark

            Write a Reply...