I have an issue with the MySQL SOURCE command. I am getting 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 query I am executing is as follows:
mysql_query('SOURCE /var/www/apps/modx_install.sql;')
I was wondering what I was doing wrong here as I have read from several sources that this is the correct syntax.
Thanks
it seems your MySQL-Server doesn't know the source command.
If you have shell access you could use
mysql --user=$user --password=$password $database < $file
You can try the same from within PHP
shell( "mysql --user=$user --password=$password $database < $file" );
Cheers.
haggi
I didn't try yet, but according to a comment at http://php.net/manual/es/function.mysql-query.php, you should use LOAD DATA INFILE as an alternative of SOURCE.
Hope it helps
mysql_query("SOURCE '/var/www/apps/modx_install.sql'")
I had the same problem (as I know SOURCE
command is only implemented in the command line tool) and running shell command was not possible. I've found the following: if the sql command is SOURCE
I cut the parameter (a filename) 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);
}
}
精彩评论