php - setting query value to null from variable -


i trying insert null values database using pdo seem having problems

code

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 book_categories          values($id, $isbn, $category, $parent)          on duplicate key update id = $id"     ); } 

there instances parent column can null none of following set parent null, instead sets value empty string "" or null string "null".

$database->addbookcategory("kujhg", "asdasd", "asdasd", null); $database->addbookcategory("kujhg", "asdasd", "asdasd", ""); $database->addbookcategory("kujhg", "asdasd", "asdasd", "null"); 

what can done overcome problem?

you should write column names

   "insert book_categories (id, isbn , category,parent)     values($id, $isbn, $category, $parent)      on duplicate key update id = $id" 

and use one

  $database->addbookcategory("kujhg", "asdasd", "asdasd", null); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -