Php PDO绑定循环索引

Php PDO绑定循环索引,php,pdo,Php,Pdo,我有一些用户上传的图像,可以排序,需要保存图像的位置。我在想,只要在遍历循环索引时使用循环索引,就可以很容易地做到这一点。但是,使用$i变量绑定第三个参数是作为引用传递的,我需要该值。我该怎么做 代码如下: $postId = $args['postId']; $images = explode(",", $args['images']); $sql = 'INSERT INTO post_image (name,postId,ordinal) VALUES '; $part = array_

我有一些用户上传的图像,可以排序,需要保存图像的位置。我在想,只要在遍历循环索引时使用循环索引,就可以很容易地做到这一点。但是,使用$i变量绑定第三个参数是作为引用传递的,我需要该值。我该怎么做

代码如下:

$postId = $args['postId'];
$images = explode(",", $args['images']);

$sql = 'INSERT INTO post_image (name,postId,ordinal) VALUES ';
$part = array_fill(0, count($images), "(?, ?, ?)");
$sql .= implode(",", $part);
logit($sql);

try{
  $db = DB::getInstance();
  $stmt = $db->dbh->prepare($sql);
  $count = count($images);
  $n = 1;
  for($i = 0; $i < $count; $i++){
    $stmt->bindParam($n++, $images[$i]);
    $stmt->bindParam($n++, $postId);
    $stmt->bindParam($n++, $i);
  }
  $result = $stmt->execute();

  if($result !== false) {
    return true;
  }else {
    logit('Query Failed');
    return false;
  }
}catch(PDOException $e) {
   logit($e->getMessage());
   return false;
}
$postId=$args['postId'];
$images=explode(“,”,$args['images']);
$sql='插入post_图像(名称、postId、序号)值';
$part=数组填充(0,计数($images),“(?,?,?)”;
$sql.=内爆(“,”,$part);
logit($sql);
试一试{
$db=db::getInstance();
$stmt=$db->dbh->prepare($sql);
$count=计数($images);
$n=1;
对于($i=0;$i<$count;$i++){
$stmt->bindParam($n++,$images[$i]);
$stmt->bindParam($n++,$postId);
$stmt->bindParam($n++,$i);
}
$result=$stmt->execute();
如果($result!==false){
返回true;
}否则{
logit('查询失败');
返回false;
}
}捕获(PDO$e){
logit($e->getMessage());
返回false;
}

我通过对第三个参数使用bindValue修复了它