在编码时我真的很模糊,似乎无法找出导致什么 HY093使用PDO将数据插入mysql的错误
function whatever($post_id, $comment) {
...
$query = "INSERT INTO `comments` (`id`, `post_id`, `comment`) VALUES (:id, post_id,:comment)";
$sql = $db->prepare($query);
$check = $sql->execute(array(':id'=>'',
':post_id'=>$post_id,
':comment'=>$comment));
//verify if data is inserted
if($check) {
$test = 'inserted';
} else {
$test = $sql->errorCode();
}
return $test;
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误HY093.
我id是自动增量,我不确定使用''是否是正确的方式来声明它.
你:之前忘记了post_id
$query = "INSERT INTO `comments` (`id`, `post_id`, `comment`)
VALUES (:id, :post_id, :comment)";
^---------------------------here
Run Code Online (Sandbox Code Playgroud)