catfan / Medoo

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

[feature] Please provide hasError() boolean method #911

Closed BurakBoz closed 3 years ago

BurakBoz commented 4 years ago

Hi,

$db->error();

this method returns an array and need some extra checks, we really need a simple boolean method to check if last query succeeded or failed. Please consider this feature.

An ugly error checking example:

$db->update("table", ["a" => "b"], ["c" => "d"]);

if (!is_null($db->error()[1]))
{
     echo "Error!";
}
else
{
     echo "Updated!";
}

A beautiful example:

$db->update("table", ["a" => "b"], ["c" => "d"]);

if($db->hasError())
{
     echo "Error!";
}
else
{
     echo "Updated!";
}
catfan commented 3 years ago

We will have this feature on next v2.0 discussed here: https://github.com/catfan/Medoo/discussions/946

You can check the error simply by this:

if ($database->error) {
    echo "having error";
}