클라이언트에 대한 정보를 저장하는 데이터베이스가 있습니다. 나는 "전화"라는 전화 번호를위한 독특한 필드를 가지고있다. 매개 변수화 된 쿼리를 사용하여 테이블에 INSERT하고 중복 키에 클라이언트 정보를 업데이트하려고합니다. 나는 철자법을 4 배 검사했고, 모든 것이 동등한 것처럼 보입니다. 계속 오류가 있습니다. "확인 ... 올바른 구문을 사용하는 곳 근처에서`Phone` =?"Parameterize Insert ... 중복 키 UP SET 의미를 사용하여 UPDATE가 실패합니다.
// These are the fields that we want to Upsert
$fields = "
`Objectives` = :objectives,
`LiquidFunds` = :liquidFunds,
`UnitNumber` = :unitNumber,
`Accredited` = :accredited,
`FirstName` = :firstName,
`LastName` = :lastName,
`Street` = :street,
`Phone` = :phone,
`Email` = :email,
`State` = :state,
`Notes` = :notes,
`City` = :city,
`Zip` = :zip
";
$updateLead = $dbHandle -> prepare("
INSERT INTO `Leads` SET $fields
ON DUPLICATE KEY UPDATE $fields WHERE `Phone` = :phoneKey"
);
그리고 나중에 나는 나는 같은에 최선을 다하는 노력했습니다
$updateLead = $dbHandle -> prepare("UPDATE `Leads` SET $fields WHERE `Phone` = :phoneKey);
에 쿼리를 변경하면 너무
// Bind our parameters to the updateLead query
$updateLead -> bindParam(":objectives" , $objectives);
$updateLead -> bindParam(":liquidFunds", $_POST['liquidFunds']);
$updateLead -> bindParam(":unitNumber" , $_POST['unitNumber']);
$updateLead -> bindParam(":accredited" , $_POST['accredited']);
$updateLead -> bindParam(":firstName" , $_POST['fname']);
$updateLead -> bindParam(":lastName" , $_POST['lname']);
$updateLead -> bindParam(":street" , $_POST['street']);
$updateLead -> bindParam(":phone" , $_POST['phone']);
$updateLead -> bindParam(":phoneKey" , $_POST['phone']);
$updateLead -> bindParam(":email" , $_POST['email']);
$updateLead -> bindParam(":state" , $_POST['state']);
$updateLead -> bindParam(":notes" , $_POST['notes']);
$updateLead -> bindParam(":city" , $_POST['city']);
$updateLead -> bindParam(":zip" , $_POST['zip']);
이 정확한 구조가 완벽하게 작동과 같은 매개 변수를 바인딩하고 줄을 긋고 똑같은 오류를 던졌습니다 (다른 "줄 번호"에서). 내가 여기서 무엇을 잘못하고 있니?
PS : 나는 PHP/PDO
'중복 키 업데이트'에 대한 설명서를 읽는 것이 맞습니까? –
따라 할 수 있을지 모르겠다. –