ezSQL / ezsql

PHP class to make interacting with a database ridiculusly easy
http://ezsql.github.io/ezsql
GNU Lesser General Public License v3.0
866 stars 291 forks source link

try catch with ezsql #209

Closed mbunal closed 3 years ago

mbunal commented 3 years ago

hi, how can i use try catch with ezsql?

mbunal commented 3 years ago

i tried with this code in lib/database/ez_sqlite3.php at the end.

    public function enableExceptions()
    {
        return $this->dbh->enableExceptions(true);
    }

i think it is working. mayde added future relases...

TheTechsTech commented 3 years ago

Already possible: https://github.com/ezSQL/ezsql/blob/4bc6a254b7ac9d4856da343682c9af14cbec8909/lib/ezsqlModel.php#L446

All errors is processed thru: https://github.com/ezSQL/ezsql/blob/4bc6a254b7ac9d4856da343682c9af14cbec8909/lib/ezsqlModel.php#L429

An exception is only throw when vendor database driver not installed, missing config settings, or using transactional database queries. Otherwise, you need to check if false is returned.

->show_errors() default state is true.

mbunal commented 3 years ago

First of all thank you.

I'm not a php guru. I just tried to enter the same value in a field that should be unique. show_errors didn't work for me but enableExceptions did. i think "show_errors" and "exceptions" are completely different error handling mechanism.

anyway. thanks for great sql interface to all.

TheTechsTech commented 3 years ago

They are different.

This library only throw exceptions as stated, you need to check a return queries for boolean false, or it will do a non catchable fatal error if warrent.

Your solution, might just be valid for that vendor sql driver, whereas, this library make all method/function calls used interchangeable.