pdo准备插入失败

时间:2011-08-12 18:30:39

标签: php mysql insert 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是一个数字数组。

我已经查看了其他答案,没有任何内容适用,我现在仍然坚持这一点,任何帮助都表示赞赏。

1 个答案:

答案 0 :(得分: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);");