Jump to content

PHP and Importing MySQL database


pcw

Recommended Posts

Hi, I am trying to import a MySQL database. I can back it up ok, but I need a way to import it with PHP. I know you can import it with phpMyAdmin, but I need a way to do this from a PHP script.

 

This is what I have got:

 

<?php
mysql_connect($dbhost, $dbuser, $dbpass) or die('Error occured whilst connecting to the server: ' . mysql_error());
mysql_select_db($db) or die('Error occured whilst selecting the MySQL database: ' . mysql_error());


$gzFile = $backupFile; 

mysql_query("LOAD DATA LOCAL INFILE $gzFile INTO *") or die('Error loading data file.<br>' . mysql_error()); 

mysql_close($db); 
?>

 

But I get this error:

 

Error loading data file.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/mysql_moveitho_sitebuilder_22_Mar_2009_time_18_41_26.sql.gz' at line 1

 

Can anyone tell me how to fix this?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/150602-php-and-importing-mysql-database/
Share on other sites

The thing is, I do need to do it myself as its part of a project im working on. Plus the export task is integrated into the script I have already written. I need to be able to integrate the import task into my script too. How would I fix the error I am getting?

 

Thanks

Well I am no pro at databases yet, so I am taking a Semi-educated guess that it could be becuase the file is still in a compressed format and needs to be decompressed prior to import so that you are importing a .sql file. Also if you download that script and look it over it may give you insight on too how you could attack your problem.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.