2014-03-28 51 views
-1

我试图检索单行以下功能:PHP得到以下错误:“致命错误:未捕获的异常‘PDOException’”

function get_registrar($key){ 
    global $db; 

    $query = 'SELECT * FROM registration WHERE key = :key'; 
    $statement = $db->prepare($query); 
    $statement->bindValue(':key', $key); 
    $statement->execute(); 
    $result = $statement->fetch(); 
    $statement->closeCursor(); 
    return $result; 
} 

而且我不断收到“致命错误:未捕获的异常'PDOException'消息'SQLSTATE [42000]:“错误消息。任何想法,为什么这可能是?由于

回答

2

关键是一个保留关键字

所以BACKTICK它作为

`key` 

$query = 'SELECT * FROM registration WHERE `key` = :keyval'; 

下面是保留关键字

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

+0

感谢的名单,我改变了$关键的东西其他,但仍然得到错误。 – Richard

+0

我可以在我的桌子上使用“钥匙”吗? – Richard

+0

没有你不能使用你的表中的密钥或大写字母的名字,如果你使用你需要返回打勾..对于绑定变量它的好 –

相关问题