Datacrawler
Datacrawler

Reputation: 2886

Save SQL data to PHP array

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()

Upvotes: 0

Views: 1139

Answers (1)

Lavi Avigdor
Lavi Avigdor

Reputation: 4182

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.
}

Upvotes: 1

Related Questions