pcw Posted March 22, 2009 Share Posted March 22, 2009 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 More sharing options...
WolfRage Posted March 22, 2009 Share Posted March 22, 2009 Want to solve the problem with out having to do it yourself, try bigdump.php . Plus that script can give you some good pointers. Just google bigdump.php, a very useful script. Link to comment https://forums.phpfreaks.com/topic/150602-php-and-importing-mysql-database/#findComment-791095 Share on other sites More sharing options...
pcw Posted March 22, 2009 Author Share Posted March 22, 2009 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 Link to comment https://forums.phpfreaks.com/topic/150602-php-and-importing-mysql-database/#findComment-791099 Share on other sites More sharing options...
WolfRage Posted March 22, 2009 Share Posted March 22, 2009 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. Link to comment https://forums.phpfreaks.com/topic/150602-php-and-importing-mysql-database/#findComment-791101 Share on other sites More sharing options...
pcw Posted March 22, 2009 Author Share Posted March 22, 2009 ok, good idea Thanks WolfRage Link to comment https://forums.phpfreaks.com/topic/150602-php-and-importing-mysql-database/#findComment-791104 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.