Jump to content

Problem importing sql file through php


elis

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/169100-problem-importing-sql-file-through-php/
Share on other sites

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

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.