MySQL SOURCE Error

I have a problem with the MySQL SOURCE team. I get the following error:

1064: 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 'SOURCE /var/www/apps/modx_install.sql' at line 1 

The executed request is as follows:

 mysql_query('SOURCE /var/www/apps/modx_install.sql;') 

I was wondering what I am doing wrong here, as I have read from several sources that this is the correct syntax.

thanks

+4
source share
4 answers

It seems that your MySQL server does not know the original command.

If you have shell access, you can use

 mysql --user=$user --password=$password $database < $file 

You can try the same thing from PHP

 shell( "mysql --user=$user --password=$password $database < $file" ); 

Greetings.
haggi

+6
source
 mysql_query("SOURCE '/var/www/apps/modx_install.sql'") 
0
source

I had the same problem (as I know, the SOURCE command is only implemented in the command line tool) and running the shell command is not possible. I found the following: if the sql command is SOURCE , I truncate the parameter (file name) and try to process it. (I use my own mysql library, db_Exec() has the same effect as mysql_query() .)

  function db_Exec_plus($query) { $tmp = explode(" ", trim($query), 2); if(isset($tmp[0]) && strtoupper(trim($tmp[0]))=='SOURCE') { if (isset($tmp[1]) && file_exists($tmp[1])) { $result_array = array(); $fp = fopen($tmp[1], "r"); while (!feof($fp)) { $cmd = trim(fgets($fp)); $result_array[] = db_Exec($cmd); } fclose($fp); return $result_array; } else { return false; } } else { return db_Exec($query); } } 
0
source

I haven't tried it yet, but according to the comment http://php.net/manual/es/function.mysql-query.php you should use LOAD DATA INFILE as an alternative to SOURCE,

Hope this helps

0
source

All Articles