PHP 中的 MySQL 错误,但不是通过 CLI

发布于 2024-10-06 12:22:17 字数 1464 浏览 6 评论 0原文

更新: 我发现了问题,我将 sql 语句输出到文件而不是屏幕上,并注意到 sql 语句末尾有一个额外的隐藏字符。一旦我删除查询工作正常。从网上剪切并粘贴该声明就忽略了这一点。感谢您的帮助。 固定的。

我收到来自 mysql 的 1064 错误,查询如下:

    update `table` set `id` = "152614",
`Field2` = "151",
`Field3` = "11",
`Field4` = "1587",
`Field5` = "Elevator",
`Field6` = "",
`Field7` = "",
`Field8` = "",
`Field9` = "",
`Field10` = "",
`Field11` = "",
`Field12` = "0",
`Field13` = "0",
`Field14` = "0",
`Field15` = "0",
`Field16` = "0",
`Field17` = "0",
`Field18` = "0",
`Field19` = "0",
`Field20` = "0",
`Field21` = "0",
`Field22` = "0",
`Field23` = "0",
`Field24` = "0",
`Field25` = "0",
`Field26` = "0",
`Field27` = "0",
`Field28` = "0",
`Field29` = "0",
`Field30` = "0",
`Field31` = "0",
`Field32` = "0",
`Field33` = "0",
`Field34` = "0",
`Field35` = "0",
`Field36` = "1065353216",
`Field37` = "0",
`Field38` = "0",
`Field39` = "0",
`Field40` = "0",
`Field41` = "0",
`Field42` = "0",
`Field43` = "0" where id ="152614"

MySQL 错误 1064:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 43 行 '' 附近使用的正确语法

。 第 43 行是最后一行。

如果我将它粘贴到 mysql CLI 中,它工作正常:

查询正常,1 行受影响(0.00 秒) 匹配的行:1 更改:1 警告:0

此时我不知所措,有什么想法吗?谢谢。

MySQL 版本:5.1.52 PHP 版本:5.3.3

它在我的脚本中相当深,但产生错误的部分是:

$result  = mysql_query( $sql );
if (mysql_errno()) { 
echo  "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing <br>\n$sql\n<br>";

如果我输出 $sql,它与上面查询的粘贴相同(上面来自错误行)。

Update:
I found the problem, I output the sql statement to a file instead of on the screen and noticed an extra hidden char towards the end of the sql statement. Once I removed that the query worked fine. Cutting and pasting the statement from the web was omitting that. Thanks for the help.
Fixed.

I receive a 1064 error from mysql with the following query:

    update `table` set `id` = "152614",
`Field2` = "151",
`Field3` = "11",
`Field4` = "1587",
`Field5` = "Elevator",
`Field6` = "",
`Field7` = "",
`Field8` = "",
`Field9` = "",
`Field10` = "",
`Field11` = "",
`Field12` = "0",
`Field13` = "0",
`Field14` = "0",
`Field15` = "0",
`Field16` = "0",
`Field17` = "0",
`Field18` = "0",
`Field19` = "0",
`Field20` = "0",
`Field21` = "0",
`Field22` = "0",
`Field23` = "0",
`Field24` = "0",
`Field25` = "0",
`Field26` = "0",
`Field27` = "0",
`Field28` = "0",
`Field29` = "0",
`Field30` = "0",
`Field31` = "0",
`Field32` = "0",
`Field33` = "0",
`Field34` = "0",
`Field35` = "0",
`Field36` = "1065353216",
`Field37` = "0",
`Field38` = "0",
`Field39` = "0",
`Field40` = "0",
`Field41` = "0",
`Field42` = "0",
`Field43` = "0" where id ="152614"

MySQL 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 '' at line 43

Line 43 is the last line.

If I paste it into the mysql CLI it works fine:

Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

At this point I'm at a loss, any ideas? Thanks.

MySQL Version: 5.1.52
PHP Version: 5.3.3

It's fairly deep in my script, but the part that produces the error is:

$result  = mysql_query( $sql );
if (mysql_errno()) { 
echo  "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing <br>\n$sql\n<br>";

If I output $sql, it's identical to the paste for the query above ( above is from the error line ).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情愿 2024-10-13 12:22:17

我发现了问题,我将 sql 语句输出到文件而不是屏幕上,并注意到 sql 语句末尾有一个额外的隐藏字符。一旦我删除查询工作正常。从网上剪切并粘贴该声明就忽略了这一点。感谢您的帮助。固定的。

I found the problem, I output the sql statement to a file instead of on the screen and noticed an extra hidden char towards the end of the sql statement. Once I removed that the query worked fine. Cutting and pasting the statement from the web was omitting that. Thanks for the help. Fixed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文