我正在开发一个简单的shooping系统,并使用PDO.
但是在使用多个值进行更新时,我似乎无法使用PDO ……
看这里 :
// GET MESSAGES ID AND REPLACE '-' WITH ','
$mid = explode("," , str_replace( '-' , ',' , $mid ));
$isread = "read";
$stmt = $conn->prepare("UPDATE `mshop_pms` SET `readperm` = ? WHERE `mid` IN (?)");
$stmt->execute(array($isread, array($mid)));
我怎样才能做到这一点?这样做:
$stmt->execute(array($isread, $mid));
没有爆炸它只是更新第一行.
提前致谢.
解决方法:
它不会以这种方式工作.您需要遍历爆炸的数组,然后继续更新.
这是一个例子: –
// GET MESSAGES ID AND REPLACE '-' WITH ','
$mid = explode("," , str_replace( '-' , ',' , $mid ));
$isread = "read";
try
{
$stmt = $conn->prepare("UPDATE `mshop_pms` SET `readperm` = :readperm WHERE `mid` = :mid");
}
catch(PDOException $e)
{
echo $e->getMessage();
}
//Now update and iterate
foreach($mid as $m)
{
$s->bindParam(':readperm', $isread);
$s->bindParam(':mid', $m);
$s->execute();
}