查询失败:SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配

时间:2012-09-11 20:32:08

标签: php pdo

我在数据库中使用PDO和UPDATING多个表。每次执行查询时,都会收到以下错误:

查询失败:SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配

我经历过检查,似乎是正确的。我可以在PHPMyAdmin中使用硬值运行查询,它将更新表。我已经对表名进行了硬编码以进行测试。

                $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() );
            }
          }

不确定我做错了什么。我希望有一个人可以帮助我。

1 个答案:

答案 0 :(得分:7)

您似乎没有在任何地方设置:id_employee