|--id--|--uid--|--pid--|--show--| 我正在做这个插入序列: $icat_sth = $dbh->prepare("INSE-6ren">
gpt4 book ai didi

php - 使用 "show"作为字段名称时尝试插入行的语法错误

转载 作者:行者123 更新时间:2023-12-01 00:11:41 25 4
gpt4 key购买 nike

我有一张 table :

up_rel

> |--id--|--uid--|--pid--|--show--|

我正在做这个插入序列:

 $icat_sth = $dbh->prepare("INSERT INTO product_category (name, parent) VALUES(:name, :parent)");
$icat_sth->bindParam(':name', $post['cat_name']);
$icat_sth->bindParam(':parent', $post['parent_category']);
$icat_sth->execute();
$pid = $dbh->lastInsertId();

$rel_sth = $dbh->prepare("INSERT INTO up_rel (uid, pid, show) VALUES(:uid, :pid, :show)");
$rel_sth->bindParam(':uid', $uid);
$rel_sth->bindParam(':pid', $pid);
$rel_sth->bindParam(':show', '1');
$rel_sth->execute();
echo $dbh->lastInsertId();

第一次插入产品类别很顺利,但下一次插入返回错误:

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 'show) VALUES(?, ?, ?)' at line 1

如果我从插入内容中删除节目,它会起作用。

我试过把一个放在值 (:uid, :pid, 1)在绑定(bind)中我引用了它而不是。

有什么我想念的吗?

最佳答案

Show 是 MySQL 中的保留字,所以我假设这就是您看到的错误:http://dev.mysql.com/doc/refman/5.0/en/show.html .

根据@Burhan Khalid 的贡献(如果您无法重命名该字段,这是一个不错的选择):

To escape reserved words, use back ticks ``.

@newfurniturey 有一个更有用的保留字引用:

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

关于php - 使用 "show"作为字段名称时尝试插入行的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15331183/

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