将 SQL 数据保存到 PHP 数组

Save SQL data to PHP array

我想将数据从 SQL table 提取到我的 PHP 脚本中的数组。我需要它,因为在那之后我想比较两个 tables。

$sql = "select date, sum(clicks) from Table group by date";

$query = $Db->query($sql);

$result = array(); // Script does not work even if I remove this line

$result = $query->fetchAll();

print_r($result);

我遇到错误:

PHP Fatal error: Call to undefined method mysqli_result::fetchAll()

正如@Mark所说,使用

$result = $query->fetch_all();

对于 PHP 5.3.0 之前的 PHP 版本,使用:

while ($row = $result->fetch_assoc()) {
    // do what you need.
}