elis Posted August 6, 2009 Share Posted August 6, 2009 I haven't used this feature before so I'm unsure whether my syntax is correct (I'm assuming it isn't because of my errors.) I've searched around for the correct syntax to use, but haven't found it. Here's the error I'm receiving: 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 '' at line 1 and here is my code <?php require($configRoot); $import = mysql_query("LOAD DATA INFILE '$absolutePath/install/import/tables.sql'"); if($import) { $results[] = '<td align="center"><img src="images/tick.png"></td><td align="left">Imported database tables.</td><tr>'; } else { $results[] = '<td align="center"><img src="images/cross.png"></td><td align="left">Unable to import tables</td><tr>'; echo mysql_error(); } ?> I've tried using: $import = mysql_query("LOAD DATA INFILE '".$absolutePath."/install/import/tables.sql'"); and $import = mysql_query("LOAD DATA INFILE ".$absolutePath."/install/import/tables.sql"); but receive the same error. Quote Link to comment https://forums.phpfreaks.com/topic/169100-problem-importing-sql-file-through-php/ Share on other sites More sharing options...
alexdemers Posted August 6, 2009 Share Posted August 6, 2009 I think LOAD DATA INFILE is only to populate tables and not a database. According to MySQL :: MySQL 5.1 Reference Manual, it seems that "INTO TABLE tbl_name" is a requirement. So, change your file/query to that accordingly. So: mysql_query("LOAD DATA INFILE '$absolutePath/install/import/tables.sql' INTO TABLE tbl_name"); If you want to import the whole SQL file, then I'd suggest to use the mysql cli: mysql -p -h DBserber DBname < tables.sql Quote Link to comment https://forums.phpfreaks.com/topic/169100-problem-importing-sql-file-through-php/#findComment-892184 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.