【发布时间】:2011-10-25 23:40:33
【问题描述】:
我目前正在通过切换到 PDO 来更新我的应用。我有以下代码:
$stmt = $db->prepare("select * from `product` where productid in (:productidLst)");
$stmt->bindParam(":productidLst",$productidLst, PDO::PARAM_INT);
$stmt->execute();
上述代码之后的 var $productidLst 是 1,2 我想使用与此等效的 PDO:
while($rs=mysql_fetch_assoc($res)){
$rs['qty']=$_SESSION['basket'][$rs['productid']];
$rs['total'] += $rs['qty']*$rs['price'];
$total += $rs['total'];
$a[] = $rs;
}
我已经尝试了许多组合,但都没有成功,因此我们将不胜感激(在第二个代码块中 $res 是 sql)。其次,我将参数 $productidLst 设置为 INT 这是正确的还是应该是字符串?
--------更新 1------------- --------------------------
我已经尝试了以下代码:
$stmt = $db->prepare("select * from `product` where productid in (:productidLst)");
foreach ($stmt->execute(array(':productidLst' => $productidLst)) as $row)
{
$total += $row['total'];
}
返回:foreach() 错误提供的参数无效
【问题讨论】:
-
PDOStatement::execute()返回一个不适合在foreach中使用的布尔值