Hi, I want to use prepared statements for my db calls, but was wondering if anyone knew of a wrapper or subclass for mysqli to make my code a little more manageable. Anyone know of one?

Thanks,
b

    In what way do you find MySQLi not so manageable?

      I think I'll look into PEAR. I like mysqli, but in my system I'm making a lot of db calls and would like to call maybe one or 2 lines for every prepared statement instead of about 10 lines that would do the calls and error handling.

        For example, I'd like something like this:

        $db = new DBCLASS($host,$user,$pass,$database);

        if( $results = $db->query($sql,$table) ) {
        //do some stuff
        }
        else {
        //exit
        }

        With this the errors would be handled by the query function instead of writing the lines for the error handling for every call.

        Any thoughts?

          You could use the PDO extension and turn on its exceptions, upon which you can leave the corresponding exception handling to one specific one point in your script instead of handling it at each SQL statement execution.

            Another approach is simply to extend the MySQLi class and add any custom methods you want to use.

              Thanks NogDog, that's exactly what I ended up doing. Works just like I wanted!

              b

                burnside wrote:

                Thanks NogDog, that's exactly what I ended up doing.

                Yes, it's called "programming" 😃

                  Write a Reply...