mysql 查询不起作用(同时运行两个 INSERT)
当我运行这个时,我的代码中有一些查询
...
echo $query;
mysql_query($query)
or die(mysql_error());
,输出以下内容:
INSERT INTO test ( c1, c2, c3, c4, c5)
VALUES ('xo', 'VxbcS','rzDMœSfsg', 'œsAcdiNwu','axaWMYOOj');
INSERT INTO test ( c1, c2, c3, c4, c5)
VALUES ('ihTnUcBU', 'plKtJdsRT','PyJUPBx', 'f','SspBuWJiK');
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 test ( c1, c2, c3, c4, c5) VALUES ('ihTnUcBU', 'plKtJdsRT',' at line 3
如果我复制上面的插入查询并直接在 phpmyadmin 中运行它,它的工作没有任何问题。但当我运行 php 代码时它不起作用,有人知道这里似乎出了什么问题吗?谢谢你的帮助。
I have some query in my code
...
echo $query;
mysql_query($query)
or die(mysql_error());
when I run this,output the following:
INSERT INTO test ( c1, c2, c3, c4, c5)
VALUES ('xo', 'VxbcS','rzDMœSfsg', 'œsAcdiNwu','axaWMYOOj');
INSERT INTO test ( c1, c2, c3, c4, c5)
VALUES ('ihTnUcBU', 'plKtJdsRT','PyJUPBx', 'f','SspBuWJiK');
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 test ( c1, c2, c3, c4, c5) VALUES ('ihTnUcBU', 'plKtJdsRT',' at line 3
if I copy the insertion query above and run it directly in phpmyadmin, it works without any problem. but it does not work when I run the php code, does any body know what seems to be wrong here? thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您一次只能运行一个查询。
或使用多插入查询
You can run just one query at time.
or use a multi-insert query
Nick 是正确的,您只能使用 mysql_query 一次运行 1 个查询。您是否考虑过使用存储过程(例程)来实现此目的?另外,您看过 PDO 吗?
Nick is correct, you can only run 1 query at a time with mysql_query. Have you considered using a stored procedure (routine) to achieve this? Also, have you ever looked at PDO?