catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Version 0.9.6 to Version 1.0.2 => FetchAll #378

Closed keldon2295 closed 6 years ago

keldon2295 commented 8 years ago

Hello,

I was on version 0.9.6 and recently updated the file to the newest version. Upon doing so query's started to fail with the following error: Fatal error: Call to a member function fetchAll() on boolean in

The query runs perfectly fine on the older version but fails on the newer versions. Any thoughts;

$data = $dbConn->query("SELECT * FROM EVENTDB.domains d WHERE d.domain_id='7')->fetchAll(PDO::FETCH_ASSOC);

cejayassoc commented 7 years ago

Did you ever get an answer to this? I am having a similar problem in our project. Everything has been working for some time and suddenly I get the error:

Fatal error: Call to a member function fetchAll() on a non-object in *****

y2k4ever commented 7 years ago

I also have similar problem..currently using medoo v 0.9. The error started when i upgraded mysql from 5.5 to 5.7. Please share if you guys have a solution.

Andrews54757 commented 7 years ago

It returns false if in debug mode - or if the query doesnt work -

https://github.com/catfan/Medoo/blob/master/src/Medoo.php#L279-L318

Andrews54757 commented 7 years ago

Compare:

Old:

https://github.com/catfan/Medoo/blob/11680a33b4cd741563cb0f1ec3bf583e17fb2140/src/Medoo.php#L299-L310

New:

https://github.com/catfan/Medoo/blob/6798b9698ee60ee98a4d342485904322922b2b3b/src/Medoo.php#L299-L317

Andrews54757 commented 7 years ago

@y2k4ever , @keldon2295 . To fix, all you need to do is replace the above with the old version

cejayassoc commented 7 years ago

My problem was with a query, in my case, there was a missing parameter. My actual problem was that I was hiding a section of content from myself and couldn't see what was really going on.

Andrews54757 commented 7 years ago

@cejayassoc You problem is a different problem than the problem addressed in this issue. I cannot figure out what you mean due to lack of information

catfan commented 7 years ago

The query() will return false if preparation pdo->prepare() is failed. https://github.com/catfan/Medoo/issues/588

You can check the statement before next operation.

$statement = $database->query("SELECT * FROM EVENTDB.domains d WHERE d.domain_id='7'");

if ($statement)
{
    $data = $statement->fetchAll(PDO::FETCH_ASSOC);
}