我正在尝试使用 PDO 将空值插入数据库,但似乎有问题
代码
public function addBookCategory($id, $isbn, $category, $parent){
$id = $this->dbh->quote($id);
$isbn = $this->dbh->quote($isbn);
$category = $this->dbh->quote($category);
$parent = $this->dbh->quote($parent);
return $this->query(
"INSERT INTO book_categories
VALUES($id, $isbn, $category, $parent)
ON DUPLICATE KEY UPDATE id = $id"
);
}
在某些情况下,父列可以为空,但以下均未将父列设置为空,而是将值设置为空字符串“”或空字符串“NULL”。
$database->addBookCategory("kujhg", "asdasd", "asdasd", NULL);
$database->addBookCategory("kujhg", "asdasd", "asdasd", "");
$database->addBookCategory("kujhg", "asdasd", "asdasd", "NULL");
可以做些什么来克服这个问题?