[英]PHP Getting the following error: “Fatal error: Uncaught exception 'PDOException' ”
I'm trying to retrieve a single row with the following function: 我正在尝试使用以下功能检索一行:
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;
}
And I keep getting "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:" error messages. 而且我不断收到“致命错误:消息为'SQLSTATE [42000]的未捕获异常'PDOException':”错误消息。 Any idea why this might be? 知道为什么会这样吗? Thanks 谢谢
key is a reserved key word 键是保留的关键字
so backtick it as 所以回勾它为
`key`
$query = 'SELECT * FROM registration WHERE `key` = :keyval';
Here is the list of reserved keywords 这是保留关键字的列表
https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html https://dev.mysql.com/doc/refman/5.5/zh-CN/reserved-words.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.