2011-12-16 4 views
0

は[OK]を、ので、ここで...PDOとbindParam問題は

public function insert_cover($title, $description, $category_id, $filename) 
{ 
    if($this->category_exists($category_id)) { 
     $sth = $this->con->prepare(' 
      INSERT INTO cover 
      (id, title, description, image, category_id, timestamp) 
      VALUES 
      (null, :title, :description, :image, :category_id, null) 
     '); 

     $sth->bindParam(':title', $title, PDO::PARAM_STR); 
     $sth->bindParam(':description', $description, PDO::PARAM_STR); 
     $sth->bindParam(':image', $filename); 
     $sth->bindParam('::category_id', $category_id, PDO::PARAM_INT); 

     $sth->execute(); 

     return true; 
    } else { 
     return false; 
    } 
} 

私のコードであり、ここで私のエラーです:私はbindParamを使用して追加しない場合

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /MAMP/htdocs/*****/lib/DB.class.php on line 44 

それが正常に動作しますキーの配列=>値の組み合わせ​​

ここで何が起こっているのですか?

答えて

3

おそらく$sth->bindParam('::category_id', $category_id, PDO::PARAM_INT); 正しいのタイプミス:$sth->bindParam(':category_id', $category_id, PDO::PARAM_INT);

+0

20分間タイプミスがあります。長い一日だった。ありがとうございました。 – GV1

+0

そこには、それを行った! :D幸運! –

0

あなたはcategory_idのための2つのコロンを持っています。

関連する問題