catfan / Medoo

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

Why not throw an exception? #798

Closed harryleee closed 3 years ago

harryleee commented 5 years ago

i try to set a incorrect field.

$result = $db->insert($this->table, $data);
var_dump($result); // PDOStatement {...}
var_dump($db->id()); // 0
// id or result both is not FALSE !

so, I can only judge this way.

if ($db->error()[0] != '0000') {
    throw new \Exception($db->error()[2]);
}

I even 'if' the code wherever use medoo, can't handle it at a time ? thanks.

catfan commented 5 years ago

$result is a PDOStatement object. You can call its rowCount() to check out the error.

$result = $db->insert($this->table, $data);

if ($result->rowCount() > 0)
{
    // Do something
}
IP-Developer commented 5 years ago

I extended Medoo with a class of mine that checks if there are errors after Medoo::exec() and throws an exception.