【问题标题】:Save SQL data to PHP array将 SQL 数据保存到 PHP 数组
【发布时间】:2016-03-13 11:15:29
【问题描述】:

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

$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 致命错误:调用未定义方法 mysqli_result::fetchAll()

【问题讨论】:

标签: php sql fetchall


【解决方案1】:

正如@Mark 所说,使用

$result = $query->fetch_all();

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

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

【讨论】:

  • PHP 致命错误:调用未定义的方法 mysqli_result::fetch_all()
  • 我已经编辑了回复。也请发布您的 PHP 版本。
猜你喜欢
  • 2016-02-12
  • 1970-01-01
  • 2012-09-29
  • 1970-01-01
  • 2011-12-17
  • 1970-01-01
  • 2010-12-31
  • 2018-02-17
  • 1970-01-01
相关资源
最近更新 更多