简体   繁体   English

即使查询语法正确,MySQL也会抛出错误

[英]MySQL throws error even though query syntax is correct

This has got be stumped. 这已经难倒了。 I've almost literally copied this query directly into heidiSQL's query field and run it successfully. 我几乎将这个查询直接复制到heidiSQL的查询字段中并成功运行它。

I'm getting this error 我收到了这个错误

You have an error in your SQL syntax; 您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '; 检查与您的MySQL服务器版本对应的手册,以便在'附近使用正确的语法;

 INSERT INTO dots(`name`, `sambandsnr`, `dslam`, `ip`, `lat`, `lng`, `on' at line 1 

On this query 在这个查询上

DELETE FROM dots;

INSERT INTO dots(`name`, `sambandsnr`, `dslam`, `ip`, `lat`, `lng`, `online`)
VALUES
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "..."),
    ("...", "...", "...", "...", "...", "...", "...");

The real script has real data and around 800 rows. 真正的脚本有真实的数据和大约800行。 Seriously, I have copy&pasted the first 10 rows and run the query manually successfully. 说真的,我已经复制并粘贴前10行并成功手动运行查询。 That completely stumps me as to how there can be an error at line 1. 这完全让我觉得第1行可能会出现错误。

Any help would be appreciated 任何帮助,将不胜感激


Edit: I just copied the ENTIRE failing script into the query editor and ran it. 编辑:我刚刚将整个失败的脚本复制到查询编辑器中并运行它。 It ran successfully. 它运行成功。 !?!?!? !?!?!?

You seem to send two queries at once. 您似乎一次发送两个查询。

Either send them separately, or use a multi-query function to do that ( mysqli_multi_query in PHP ). 要么单独发送它们,要么使用多查询函数来完成它( PHP mysqli_multi_query )。

To do this you have to use MySQLi extension: MySQL extension is not able to send multiple queries in one statement. 要做到这一点,你必须使用MySQLi扩展: MySQL扩展无法在一个语句中发送多个查询。

From the documentation : 文档

mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier. mysql_query()向与指定link_identifier关联的服务器上的当前活动数据库发送唯一查询(不支持多个查询)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM