2013-03-11 29 views
0

我有一个表:语法错误尝试使用时,“秀”的字段名中插入一行

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) 和在我已经引用它的绑定而不是。

有什么我失踪?

+0

$ uid在脚本的前面设置.. $ pid是从第一个插入的最后一个插入标识中设置的。如果我删除节目,它的作品..? – 2013-03-11 04:33:15

回答

7

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

+2

您应该添加到您的答案,以避免保留字,使用返回滴答声'' – 2013-03-11 04:32:29

+2

此外,一个链接到MySQL保留字页:http://dev.mysql.com/doc/refman/5.5/en/reserved- words.html – newfurniturey 2013-03-11 04:32:44

+0

好嘛!!!那是它...谢谢.. @newfurniturey - 收藏夹;-) – 2013-03-11 04:36:31

相关问题