0

I am using PDO and UPDATING multiple tables in a database. Each time I execute the query I receive the following error:

Query failed: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

I have gone through and checked and it seems to be correct. I can run the query in PHPMyAdmin with hard values and it will update the tables. I have hard coded the table names for testing.

                $conn = parent::connect();
            $sql = "UPDATE ds_employee 
                    LEFT OUTER JOIN ds_employee_address ON ds_employee.id_employee = ds_employee_address.fk_employee
                    LEFT OUTER JOIN ds_employee_detail ON ds_employee.id_employee = ds_employee_detail.fk_employee
                    SET 
                      ds_employee.emp_lastname = :emp_lastname,
                      ds_employee.emp_firstname = :emp_firstname,
                      ds_employee.emp_middlename = :emp_middlename,
                      ds_employee.emp_prefername = :emp_prefername,
                      ds_employee_address.address1 = :address1,
                      ds_employee_address.address2 = :address2,
                      ds_employee_address.city = :city,
                      ds_employee_address.state = :state,
                      ds_employee_address.postal_code = :postal_code,
                      ds_employee_address.country = :country,
                      ds_employee_detail.hphone = :hphone,
                      ds_employee_detail.wphone = :wphone,
                      ds_employee_detail.mphone = :mphone,
                      ds_employee_detail.emp_email = :emp_email,
                      ds_employee_detail.gender = :gender,
                      ds_employee_detail.DOB = :DOB,
                      ds_employee_detail.ssn = :ssn,
                      ds_employee_detail.ethnicity = :ethnicity,
                      ds_employee_detail.filing_staus = :filing_status,
                      ds_employee_detail.emp_sdate = :emp_sdate,
                      ds_employee_detail.fk_department = :fk_department,
                      ds_employee_detail.job_title = :job_title,
                      ds_employee_detail.fk_manager = :fk_manager,
                      ds_employee_detail.drug_test = :drug_test,
                      ds_employee_detail.bg_check = :bg_check
                    WHERE  ds_employee.id_employee = :id_employee"; 

            try {
              $st = $conn->prepare( $sql );
              $st->bindValue( ":emp_lastname", $this->data["emp_lastname"], PDO::PARAM_STR );
              $st->bindValue( ":emp_firstname", $this->data["emp_firstname"], PDO::PARAM_STR );
              $st->bindValue( ":emp_middlename", $this->data["emp_middlename"], PDO::PARAM_STR );
              $st->bindValue( ":emp_prefername", $this->data["emp_prefername"], PDO::PARAM_STR );
              $st->bindValue( ":address1", $this->data["address1"], PDO::PARAM_STR );
              $st->bindValue( ":address2", $this->data["address2"], PDO::PARAM_STR );
              $st->bindValue( ":city", $this->data["city"], PDO::PARAM_STR );
              $st->bindValue( ":state", $this->data["state"], PDO::PARAM_STR );
              $st->bindValue( ":postal_code", $this->data["postal_code"], PDO::PARAM_STR );
              $st->bindValue( ":country", $this->data["country"], PDO::PARAM_STR );
              $st->bindValue( ":hphone", $this->data["hphone"], PDO::PARAM_STR );
              $st->bindValue( ":wphone", $this->data["wphone"], PDO::PARAM_STR );
              $st->bindValue( ":mphone", $this->data["mphone"], PDO::PARAM_STR );
              $st->bindValue( ":emp_email", $this->data["emp_email"], PDO::PARAM_STR );
              $st->bindValue( ":gender", $this->data["gender"], PDO::PARAM_STR );
              $st->bindValue( ":DOB", $this->data["DOB"], PDO::PARAM_STR );
              $st->bindValue( ":ssn", $this->data["ssn"], PDO::PARAM_STR );
              $st->bindValue( ":ethnicity", $this->data["ethnicity"], PDO::PARAM_INT );
              $st->bindValue( ":filing_status", $this->data["filing_status"], PDO::PARAM_STR );
              $st->bindValue( ":emp_sdate", $this->data["emp_sdate"], PDO::PARAM_INT );
              $st->bindValue( ":fk_department", $this->data["fk_department"], PDO::PARAM_INT );
              $st->bindValue( ":job_title", $this->data["job_title"], PDO::PARAM_STR );
              $st->bindValue( ":fk_manager", $this->data["fk_manager"], PDO::PARAM_STR );
              $st->bindValue( ":drug_test", $this->data["drug_test"], PDO::PARAM_STR );
              $st->bindValue( ":bg_check", $this->data["bg_check"], PDO::PARAM_STR );

              $st->execute();
              parent::disconnect( $conn );
            } catch ( PDOException $e ) {
              parent::disconnect( $conn );
              die( "Query failed: " . $e->getMessage() );
            }
          }

Not sure what I am doing wrong. I hope someone can help me.

4

1 回答 1

7

You don't seem to be setting :id_employee anywhere.

于 2012-09-11T20:33:24.080 回答