PDO에 가기로 결심했습니다. 아래 함수는 테이블의 행을 다른 데이터베이스 (스테이징에서 프로덕션으로)로 이동 한 다음 스테이징에서 해당 행을 삭제해야합니다. 완전히 분리 된 2 개의 데이터베이스입니다.PDO가 행을 다른 데이터베이스로 이동할 수 없습니다.
행을 가져 와서 프로덕션 데이터베이스에 삽입 할 수 있지만 준비 데이터베이스의 행이 삭제되지 않고 행의 ID 인 잘못된 필드 이름 343이 표시됩니다. 왜 그것이 그것이 사실 값인 fieldname이라고 생각하는지 확신 할 수 없다.
나에게도 더 나은 모범 사례를 주시기 바랍니다. 나는 esspecially 내가이 탈출 문제라고 가정하고 예외
private function moveCallToProduction() {
try {
$array = array(":id" => $this->call['info']['call_id']);
$sql = "SELECT * FROM `calls` WHERE `id`=:id";
$query = $this->staging->prepare($sql);
$query->execute($array);
$row = $query->fetch(PDO::FETCH_NUM);
try {
$sql = "INSERT INTO `calls` (`id`,`sip_id`,`extension`,`caller_id`,`stage`,`status`,`survey_id`,`start`,`answer`,`hangup`) VALUES (`?`,`?`,`?`,`?`,`?`,`?`,`?`,`?`,`?`,`?`)";
$stmt = $this->production->prepare($sql);
$stmt->execute($row);
if(!$stmt) {
throw new Exception('Unable to move the call '.$this->call['info']['call_id'].' to the production server.');
} else {
try {
$sql = "DELETE FROM `calls` WHERE `id`='".$this->call['info']['call_id']."'";
$query = $this->staging->query($sql);
if(!$query) {
throw new Exception('Unable to delete call '.$this->call['info']['call_id'].' from the staging server.');
}
}
catch(PDOException $e) {
$this->informer("FATAL",$e->getMessage());
}
}
}
catch(Exception $e) {
$this->informer("FATAL",$e->getMessage());
}
}
catch(PDOException $e) {
$this->informer("FATAL","We're unable to transport the call from the staging to production server. Error: ".$e->getMessage());
}
}
는'echo'에'$ sql' 변수를 시도하고 포함 된 내용을 참조하십시오. –
한가지 더, id 값을 작은 따옴표로 묶어야합니까? –
프로그래머가 준비된 명령문과 일반 쿼리를 뒤섞 었는지를 알 수 있습니다. 나는 다른 모든 (준비된) 진술이 작동하기 때문에 그것이 도망가는 문제라고 생각한다. –