以下是代码:
$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
行,但我已经测试并知道这些也是正确的。
答案 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);