2011-08-12 109 views
1

我無法獲取下面的代碼來插入數據。pdo準備的插入失敗

<?php   
    $xml_gsm = null; 
    try { 
     // normally an include 
     $data = new PDO(MYSQL_DSN, MYSQL_USERNAME, MYSQL_PASSWORD); 
     $data->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); 

     $stmt = $data->prepare("INSERT INTO tbl_sms_queue VALUES (fk_userId, fk_campaignId, message_content, gsm) VALUES (:userId, :campId, :message, :gsm);"); 
     foreach($gsms as $number): 
      $xml_gsm .= "<gsm messageId='" . $data->lastInsertId() . "'>$number</gsm>"; 
      $stmt->execute(array(':userId'=>$userId, ':campId'=>$campId, ':message'=>$message, ':gsm'=>$number)); 
      print_r($data->errorInfo()); 
     endforeach; 
    } catch(PDOException $e) { 
     echo $e->getMessage(); 
    } 
?> 

PDO errorInfo中報告00000,但沒有被插入,用戶有完整的CRUD權限,$ GSMS是數字數組。

我看了其他答案,沒有什麼適用,我現在卡在這一個,任何幫助表示讚賞。

+0

嘗試'PDO :: ERRMODE_EXCEPTION',而不是'PDO :: ERRMODE_WARNING' –

+0

@Pekka,使得不區別 –

回答

0

修正:

我:代替

$stmt = $data->prepare("INSERT INTO tbl_sms_queue VALUES (fk_userId, fk_campaignId, message_content, gsm) VALUES (:userId, :campId, :message, :gsm);"); 

$stmt = $data->prepare("INSERT INTO tbl_sms_queue (fk_userId, fk_campaignId, message_content, gsm) VALUES (:userId, :campId, :message, :gsm);");