catfan / Medoo

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

Bug: calling fetchAll method on null #976

Closed maioradv closed 3 years ago

maioradv commented 3 years ago

Information

Describe the Problem when u're using $db->query('MYQUERY')->fetchAll(\PDO::FETCH_ASSOC); if there's an error in the query the result of $db->query('MYQUERY') will be null so i cant call the method in the 1.7.10 version there isnt this problem

i could use a variable and check if there's an error or using exception, but it can be useful for silentmode have a behave like the older version

catfan commented 3 years ago

You may need to check the return object of query() (null or PDOStatement) before calling fetchAll().

$statement = $database->query('QUERY');

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

Since Medoo v2.0, it's using strict_types for strictly type checking.