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

2

1 Answer 1

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.
}
Sign up to request clarification or add additional context in comments.

2 Comments

PHP Fatal error: Call to undefined method mysqli_result::fetch_all()
I've edited the response. Please also post your PHP version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.