PDO未发布到数据库

时间:2016-07-26 01:53:57

标签: php mysql pdo

以下是代码:

$sql1 = "UPDATE muted_alerts SET `customer_id`=':customer_id', `sms_time` = '$fdate', `phone`=':phone'";

$stmt = $dbh->prepare($sql1, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY) );
$stmt->execute(array(':phone' => $phone,':customer_id'=>$customer_id));
$result1 = $stmt->fetchAll(PDO::FETCH_ASSOC);

这不会引发任何错误。我已经使用var_dump来查看$phone$fdate$customer_id是否有效且是。

我猜我的陈述中有问题。为简单起见,我排除了所有$dbh行,但我已经测试并知道这些也是正确的。

1 个答案:

答案 0 :(得分:1)

从execute方法内部数组键中的字段和冒号中删除引号。你不需要它。见下文:

$sql1 = "UPDATE muted_alerts SET customer_id=:customer_id, sms_time = :f_date, phone=:phone";

$stmt = $dbh->prepare($sql1, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY) );
$stmt->execute(array('phone' => $phone,'f_date' => '$fdate','customer_id'=>$customer_id));
$result1 = $stmt->fetchAll(PDO::FETCH_ASSOC);