Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.