mikecao / sparrow

A simple database toolkit for PHP
MIT License
289 stars 68 forks source link

Add better error handling support. #20

Closed kazzkiq closed 8 years ago

kazzkiq commented 8 years ago

For now, all I could find about handling errors when a query is executed is this piece from documentation:

When Sparrow encounters an error while executing a query, it will raise an exception with the database error message.

However, I think that maybe a more manageable approach would be interesting. Example:

$query = $db->from('user')->select()->many();

if($query->success) { // return true or false
    return $query;
} else {
    return $query->listErrors(); // array with errors
}

Some solution like the above would help make easier verifications over the query status.

mikecao commented 8 years ago

I think exceptions are the standard way to deal with errors. You can use a try-catch block and handle it however you want. The error being returned is a fatal error directly from the database so there would never be more than one.