I am using a readymade script to backup my MySQL database using PHP. I store the resultant query in a variable.
我正在使用现成的脚本来使用PHP备份我的MySQL数据库。我将结果查询存储在变量中。
If I echo the variable, and copy paste the output into the MySQL console, it works perfectly.
如果我回显变量,并将输出复制粘贴到MySQL控制台,它就可以完美地工作。
But when I run the same using 'mysql_query' (I know it is depreciated, kindly ignore that), I get the dreaded Syntax error.
但是当我使用'mysql_query'(我知道它被折旧,请忽略它)运行相同时,我得到了可怕的语法错误。
Here's the echo output (first 2 lines) :
这是回声输出(前2行):
INSERT INTO
assign
VALUES('75085','rsam','CE0001/CZ0001/CPE183/CSC183','1','1','3.0','13','1','1','13','2','10.00','117.00','0','0');INSERT INTOassign
VALUES('75086','rsam','CE0001/CZ0001/CPE183/CSC183','1','2','3.0','13','1','1','13','2','10.00','97.50','0','0');INSERT INTO指定值('75085','rsam','CE0001 / CZ0001 / CPE183 / CSC183','1','1','3.0','13','1','1','13' ,'2','10.00','117.00','0','0');插入分配值('75086','rsam','CE0001 / CZ0001 / CPE183 / CSC183','1',' 2' , '3.0', '13', '1', '1', '13', '2', '10.00', '97.50', '0', '0');
And here's the exact error :
这是确切的错误:
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 'INSERT INTO
assign
VALUES('75085','rsam','CE0001/CZ0001/CPE183/CSC183','1','1'' at line 1您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'INSERT INTO assign VALUES('75085','rsam','CE0001 / CZ0001 / CPE183 / CSC183','1','1''附近使用正确的语法第1行
If anyone can point out what I am obviously missing, I would be grateful!
如果有人能指出我明显缺少什么,我将不胜感激!
2 个解决方案
#1
3
As the documentation for mysql_query()
says:
正如mysql_query()的文档所说:
mysql_query()
sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specifiedlink_identifier
.mysql_query()向与指定link_identifier关联的服务器上的当前活动数据库发送唯一查询(不支持多个查询)。
You might be interested in mysql_multi_query()
:
您可能对mysql_multi_query()感兴趣:
Executes one or multiple queries which are concatenated by a semicolon.
执行由分号连接的一个或多个查询。
#2
2
While mysql_query
is limited to a single statement, this situation can be avoided as multiple records can be inserted into the same table with only one statement:
虽然mysql_query仅限于单个语句,但可以避免这种情况,因为只有一个语句可以将多个记录插入到同一个表中:
INSERT INTO assign (...)
VALUES(...),
VALUES(...);
This will save on round-trip latency (over multiple mysql_query
) which might matter.
这将节省往返延迟(超过多个mysql_query),这可能很重要。
See Inserting multiple rows in mysql
请参阅在mysql中插入多行
#1
3
As the documentation for mysql_query()
says:
正如mysql_query()的文档所说:
mysql_query()
sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specifiedlink_identifier
.mysql_query()向与指定link_identifier关联的服务器上的当前活动数据库发送唯一查询(不支持多个查询)。
You might be interested in mysql_multi_query()
:
您可能对mysql_multi_query()感兴趣:
Executes one or multiple queries which are concatenated by a semicolon.
执行由分号连接的一个或多个查询。
#2
2
While mysql_query
is limited to a single statement, this situation can be avoided as multiple records can be inserted into the same table with only one statement:
虽然mysql_query仅限于单个语句,但可以避免这种情况,因为只有一个语句可以将多个记录插入到同一个表中:
INSERT INTO assign (...)
VALUES(...),
VALUES(...);
This will save on round-trip latency (over multiple mysql_query
) which might matter.
这将节省往返延迟(超过多个mysql_query),这可能很重要。
See Inserting multiple rows in mysql
请参阅在mysql中插入多行