开发者

PHP PDO Insert problem

I've hit a wall with a PDO inse开发者_如何学Pythonrt:

$q = $dbh->prepare('INSERT INTO grant (grant_name, update) VALUES (?,?)');
$q->bindParam(1, $grant_name, PDO::PARAM_STR);
$q->bindParam(2, $update, PDO::PARAM_STR);
$q->execute();

I get an error:

 PHP Warning:  PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; 

But I cannot find the problem. I have tried using placeholder (such as :grant_name) and using the question marks (?).


Both GRANT and UPDATE have specific meanings in SQL. Try this:

$q = $dbh->prepare('INSERT INTO `grant` (`grant_name`, `update`) VALUES (?,?)');


Having a column name of UPDATE would appear to be your problem. Try quoting the column name (or changing the column name to something that's not a reserved word).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜