gpt4 book ai didi

php - Mysql PHP LIMIT 1 错误

转载 作者:行者123 更新时间:2023-11-29 08:15:40 25 4
gpt4 key购买 nike

我有以下代码:(php)

$alert = mysqli_query($con,"SELECT * FROM 'user_" . $row['id'] . "_notifications' LIMIT 1");

这给了我这个错误:

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 ''user_2_notifications' LIMIT 1' at line 1

请帮我解决这个问题。

最佳答案

去掉查询中表名周围的单引号:

$alert = mysqli_query($con,"SELECT * FROM user_" . $row['id'] . "_notifications LIMIT 1");

仅当表名和列名是 MySQL Reserved Words 之一时,您才需要对其进行转义。 。在这种情况下,转义字符是反勾号 (`),而不是像您在查询中那样的单引号 (')。

关于php - Mysql PHP LIMIT 1 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20646725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com