views:

149

answers:

1

Is it possible to specify that MySQLi sends any errors and warnings to the PHP default 'error_log' directive? I can't seem to find any error options for the class specification, and I don't wish to handle errors manually like so:

if ($result = $mysqli->query("...")) {  }
else
    handle $mysqli->error;
A: 

Well, one way would be to override the class:

class myMySQLi extends MySQLi {

    public function query($query, $resultmode = MYSQLI_STORE_RESULT) {
        $res = parent::query($query, $resultmode);
        if (!$res) {
            //handle error
        }
        return $res;
    }
}

Then just use as normal, except instead of creating an connection via new MySQLi(), use new myMySQLi(). Other than the error handling, it'll run just the same. I do this quite often, to throw exceptions on errors and to add additional functionality to MySQLi...

ircmaxell
hi there thanks for your reply. I suppose I could do that if it's the only option, but it seems odd to me that an error generated by the mysqli ctor can be logged to the default error_log, but any errors that occur while using the mysqli object have to be manually handled!
Spoonface