今天我在尝试进行一些查询时得到了一个不寻常的响应,这里是错误输出。
[17-Feb-2014 12:37:24 America/Denver] PHP Warning: PDOStatement::execute():
SQLSTATE[42000]: Syntax error or access violation: 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 'key = 'AH3D'' at line 1 in file on line 28
以下是我使用的代码,这就是我一直以来的做法。
public function get($key = null) {
$get = $this->conn->prepare("SELECT url FROM urls WHERE key = :get");
$get->execute(array(':get' => $key));
return $get->fetch();
}
我如何调用该函数。
echo $tiny->get($_GET['key']);
答案 0 :(得分:1)
密钥是一个mysql保留关键字,您需要在列名称key
$get = $this->conn->prepare("SELECT url FROM urls WHERE `key` = :get");