SQLSTATE[HY093] : pdo statement during insert into mysql db

后端 未结 2 1015
春和景丽
春和景丽 2020-12-21 06:27

Here it is my php code to realize insert into db:



        
相关标签:
2条回答
  • 2020-12-21 07:11

    Not sure if this is the cause of your error, but in your insert statement, CASE is a MySQL reserved word and should be escaped with backticks.

    $STH = $DBH->prepare("INSERT INTO users (name, 
                                            surname, 
                                            address, 
                                            birth_place,
                                            province,
                                            dt,
                                            sex,
                                            `case`) value (:name
                                                        :surname,
                                                        :address,
                                                        :birth_place,
                                                        :province,
                                                        :dt,
                                                        :sex,
                                                        :case)");
    
    0 讨论(0)
  • 2020-12-21 07:13

    In your query you use :dt as a placeholder, but in the class constructor you use $this->birth_date.

    Once casted, this will create an array with index 'birth_date', which doesn't match with the named parameter "dt": choose one or the other.

    0 讨论(0)
提交回复
热议问题