这似乎不会更新记录。谁能明白为什么?
try {
$status = 'OK';
$messId = 179981;
#die(var_dump($messId, $this->campaignId, $this->userId, $status));
$stmt = $this->dbh->prepare("UPDATE tbl_inbound_responses SET status = :status, sent = '1' WHERE fk_userId = :userId AND fk_campaignId = :campId AND pk_messageId = :messId") or die("Prepare Error");
$stmt->bindParam(':userId', $this->userId);
$stmt->bindParam(':campId', $this->campaignId);
$stmt->bindParam(':messId', $messId);
$stmt->bindParam(':status', $status);
$stmt->execute();
#var_dump($stmt->debugDumpParams(), $stmt->errorInfo());
if($err = $stmt->errorInfo()) {
if($err[0] != '00000') {
var_dump($stmt->debugDumpParams());
}
}
}
catch(PDOException $e) {
die($e->getMessage());
}
该脚本也有
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
设置和
$stmt->debugDumpParams();
报告:
SQL: [120] UPDATE tbl_inbound_responses SET status = :status, sent = '1' WHERE fk_userId = :userId AND fk_campaignId = :campId AND pk_messageId = :messId
Params: 4
Key: Name: [7] :userId paramno=-1 name=[7] ":userId" is_param=1 param_type=2
Key: Name: [7] :campId paramno=-1 name=[7] ":campId" is_param=1 param_type=2
Key: Name: [7] :messId paramno=-1 name=[7] ":messId" is_param=1 param_type=2
Key: Name: [7] :status paramno=-1 name=[7] ":status" is_param=1 param_type=2
NULL array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL }
干杯。
编辑:
我不相信它是:
PHP PDO Update prepared statement problem或PHP PDO Prepared statement query not updating record
答案 0 :(得分:2)
如果您没有收到异常,那么SQL查询或PDO如何破坏它没有任何问题。最可能的原因是参数问题。所以尝试调试它。只用以下内容替换->bindParam
来电:
$params = array(
':userId' => $this->userId,
':campId' => $this->campaignId,
':messId' => $messId,
':status' => $status,
);
var_dump($params);
$stmt->execute($params);
这可能会提示。如果失败,请尝试?
枚举参数。在任何情况下,使用SQL中的原始“字符串值”重新运行相同的查询以进行测试(在您选择的任何查询工具中)。
答案 1 :(得分:0)
问题!使用“,”而不是“AND”:
$stmt = $this->dbh->prepare("UPDATE tbl_inbound_responses SET status = :status, sent = 1 WHERE fk_userId = :userId, fk_campaignId = :campId, pk_messageId = :messId") or die("Prepare Error");