我有点问题,我有一个查询,我希望结果会出现在数组中。
function disponibilita($data) {
$this->sql_open();
$db=$this->db;
$sql="SELECT id FROM turni WHERE date='$data'";$stmt=$db->prepare($sql);
$stmt->execute();
$stmt->bind_result($id);
while ($stmt->fetch()) {
printf ("%s", $id);
}
} `
printf标记正确的结果,如何将这个dbquery的结果放入数组?
答案 0 :(得分:1)
查看PDO的PDOStatement::fetchAll ,或查看mysqli_result::fetch_all获取mysqli
function disponibilita($data) {
$this->sql_open();
$db=$this->db;
$sql="SELECT id FROM turni WHERE date='$data'";
$stmt=$db->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC); // for PDO
$results = $stmt->fetch_all(MYSQLI_ASSOC); // for mysqli
return $results;
}