2012-06-21 3 views
1

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

는'echo'에'$ sql' 변수를 시도하고 포함 된 내용을 참조하십시오. –

+0

한가지 더, id 값을 작은 따옴표로 묶어야합니까? –

+0

프로그래머가 준비된 명령문과 일반 쿼리를 뒤섞 었는지를 알 수 있습니다. 나는 다른 모든 (준비된) 진술이 작동하기 때문에 그것이 도망가는 문제라고 생각한다. –

답변

1

로, 우아한 같은 내 코드를보고이 작업을 수행하는 더 나은 방법이 있다고 생각하지 않습니다.

이 시도 :

... 
try { 
    $sql = "DELETE FROM `calls` WHERE `id`= :id"; 
    $stmtx = $this->staging->prepare($sql); 
    $stmtx->execute(array($this->call['info']['call_id'])); 
    if(!query) { 
... 
+0

당신의 대답은 가장 가까웠습니다. 실제로 insert 문에서 이스케이프 문제였습니다. '? '물음표가 틀렸고'? '가 드라이버 이름을 나타내는 것으로 보입니다. – mauzilla

+0

그래, 알 겠어. 물음표는''로 묶여 있습니다. 이것은 틀 렸습니다. –

관련 문제