0

これは何らかの理由で機能しません。同じループは SELECT ステートメントでは正常に機能しますが、INSERT ステートメントでは機能しません。

 $sql = "INSERT INTO users(user_id,password) VALUES(?,?)";
 $data = array();
 $data[1] = "1";
 $data[2] = "password";
 public function insert($sql,$data){
    $newQuery = $this->db->prepare($sql);
    //pass $value as a reference to the array item
    foreach ($data as $key => &$value) {  
    // bind the variable to the statement
        $newQuery->bindParam($key,$value); 
    } 
    $newQuery->execute();
}
4

0 に答える 0