[英]Syntax error trying to insert row when using “show” as field name
我有一張桌子:
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您的SQL語法錯誤; 檢查與您的MySQL服務器版本相對應的手冊,以在第1行的'show)VALUES(?,?,?)'附近使用正確的語法
如果我從插入刪除節目,它的作品。
我試過將一個放在值(:uid, :pid, 1)
並在綁定中引用而不是引用。
我有什么想念的嗎?
Show
是MySQL中的保留字,因此我認為這是您看到的錯誤: http : //dev.mysql.com/doc/refman/5.0/en/show.html 。
根據@Burhan Khalid的貢獻(如果您不能重命名該字段,這是一個不錯的選擇):
要轉義保留字,請使用反斜線``。
@newfurniturey對於保留字有更有用的參考:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.