0

I want to pull the data from a SQL table to an array in my PHP script. I need that because after that I want to compare two 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);

I am getting the error :

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

Datacrawler
  • 2,780
  • 8
  • 46
  • 100
  • 1
    `$result = $query->fetch_all();` [PHP Docs](http://www.php.net/manual/en/mysqli-result.fetch-all.php) – Mark Baker Dec 08 '15 at 13:47
  • 1
    Possible duplicate of [mysqli fetch\_all() not a valid function?](http://stackoverflow.com/questions/6694437/mysqli-fetch-all-not-a-valid-function) – Muhammad Muazzam Dec 08 '15 at 13:53

1 Answers1

1

As @Mark said, use

$result = $query->fetch_all();

For PHP version prior to PHP 5.3.0, use:

while ($row = $result->fetch_assoc()) {
    // do what you need.
}
Lavi Avigdor
  • 4,092
  • 3
  • 25
  • 28