mySQL语法错误,但是没有报错?

标签 mysql sql

<分区>

它不断收到此 SQL 错误,但我非常确定查询中没有错误。我已经盯着它看了太久了。还有其他可能导致这种情况的原因吗?

INSERT INTO game_data (clue, image, answer, wrong, right) VALUES ('asdf',         'asdf', 'asdf', 'assdf', 'asdf')

Invalid Query: 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 'right) VALUES ('asdf', 'asdf', 'asdf', 'assdf', 'asdf')' at line 1

我已经用这个确切的代码运行了其他查询,只是换掉了变量,而且它有效。

为了更好的衡量,有生成这个的 php:

$sql = "INSERT INTO game_data (clue, image, answer, wrong, right) VALUES
    ('" . $clue . "', '" . $image . "', '" . $answer . "', '" . $wrong . "', '" . $right . "')";

最佳答案

reserved keyword in MYSQL .您需要像这样使用反引号对其进行转义:

INSERT INTO game_data (`clue`, `image`, `answer`, `wrong`, `right`) VALUES

注意:以后尽量避免将您的列命名为保留关键字名称。

关于mySQL语法错误,但是没有报错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33430053/

相关文章:

php - PDO 未插入 - 无错误

mysql - 在 WHERE 子句中使用 SUM 结果时出错

php - 使用 php 和 html 选择框过滤 SQL 查询

php - 缓存index.php页面的搜索引擎有siteController但在yii PHP中没有模型

mysql - 错误 1093 : MySQL can’t specify target table for update in FROM clause

sql - 使用单个变量查询 "id"或 "slug"

sql - 过滤 CASE 语句中的 NULL 值

sql - UPDATE FROM 不适用于同一行的多次更新

SQL:HAVING 子句

mysql - 选择两个不同列的最新条目