0
我正在使用PDO和UPDATING數據庫中的多個表。每次我執行我收到以下錯誤查詢:查詢失敗:SQLSTATE [HY093]:無效的參數編號:綁定變量的數量與令牌數量不匹配
查詢失敗: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());
}
}
不知道我在做什麼錯。我希望有一個人可以幫助我。
非常感謝。那是它的一部分。我也拼寫錯了。 – REF
ds_employee_detail.filing_staus =:filing_status,應該是filing_status。但是現在提交時會刪除所有數據?任何想法? – REF
我修好了。傳遞對象時我錯過了isset – REF