PDO使用while和foreach获取

时间:2014-03-10 23:21:38

标签: php mysql pdo

我使用了你所有的tipps: 更改为,但Mysql语句没有得到值......

看看:

try {
  $sql = "SELECT a_idname FROM t_users WHERE a_zone_num <> -1;";
  $users = $conn3->query($sql);
  while ($row = $users->fetch()) {
    $result = $users->fetch(PDO::FETCH_ASSOC);
    foreach($result as $value) {
      echo $value;
      $Add_Cash = $conn1->prepare("UPDATE bg_user SET cash = cash + ':cash' WHERE user_id = ':result';");
      $Add_Cash->bindParam(':cash', $cash);
      $Add_Cash->bindParam(':result', $value);
      $Add_Cash->execute();
      $Count++;
    }
  }
  $conn3 = null;
}
catch (PDOexception $e) {
  echo "Error is: " . $e-> etmessage();
}

1 个答案:

答案 0 :(得分:1)

将$ sql更改为

$sql = "SELECT a_idname FROM t_users WHERE a_zone_num <> -1;";