Php 使用PDO将数据插入mysql,返回错误HY093
在编写代码时,我的眼睛真的很模糊,似乎无法找出是什么导致了我使用PDO将数据插入mysql时出现的Php 使用PDO将数据插入mysql,返回错误HY093,php,mysql,pdo,Php,Mysql,Pdo,在编写代码时,我的眼睛真的很模糊,似乎无法找出是什么导致了我使用PDO将数据插入mysql时出现的HY093错误 function whatever($post_id, $comment) { ... $query = "INSERT INTO `comments` (`id`, `post_id`, `comment`) VALUES (:id, post_id,:comment)"; $sql = $db->prepare($query); $check = $sql->exec
HY093
错误
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;
}
我得到这个错误HY093
我的
id
是自动递增的,我不确定使用'
是否是正确的声明方式。您忘记了:
之前的发布id
$query = "INSERT INTO `comments` (`id`, `post_id`, `comment`)
VALUES (:id, :post_id, :comment)";
^---------------------------here
您忘记了
:
之前的post\u id
$query = "INSERT INTO `comments` (`id`, `post_id`, `comment`)
VALUES (:id, :post_id, :comment)";
^---------------------------here
而不是:
`$query = "INSERT INTO `comments` (`id`, `post_id`, `comment`) VALUES (:id, post_id,:comment)";`
使用:
而不是:
`$query = "INSERT INTO `comments` (`id`, `post_id`, `comment`) VALUES (:id, post_id,:comment)";`
使用:
您可以使用NULL:
$query = "INSERT INTO `comments` (`id`, `post_id`, `comment`) VALUES (NULL, :post_id,:comment)";
或者干脆别管它:
$query = "INSERT INTO `comments` (`post_id`, `comment`) VALUES (:post_id,:comment)";
然后:
您可以使用NULL:
$query = "INSERT INTO `comments` (`id`, `post_id`, `comment`) VALUES (NULL, :post_id,:comment)";
或者干脆别管它:
$query = "INSERT INTO `comments` (`post_id`, `comment`) VALUES (:post_id,:comment)";
然后:
如果您的id是自动递增的,请不要从php脚本发送值
function whatever($post_id, $comment) {
$query = "INSERT INTO `comments` ( `post_id`, `comment`) VALUES(:id,post_id,:comment)";
$sql = $db->prepare($query);
$check = $sql->execute(array(':post_id'=>$post_id,':comment'=>$comment));
//verify if data is inserted
if($check) {
$test = 'inserted';
} else {
$test = $sql->errorCode();
}
return $test;
}
如果您的id是自动递增的,请不要从php脚本发送值
function whatever($post_id, $comment) {
$query = "INSERT INTO `comments` ( `post_id`, `comment`) VALUES(:id,post_id,:comment)";
$sql = $db->prepare($query);
$check = $sql->execute(array(':post_id'=>$post_id,':comment'=>$comment));
//verify if data is inserted
if($check) {
$test = 'inserted';
} else {
$test = $sql->errorCode();
}
return $test;
}
谢谢你指出这一点!天哪!忽略了那个小错误真的很尴尬!非常感谢。谢谢你指出这一点!天哪!忽略了那个小错误真的很尴尬!非常感谢。