Jump to content

Handling Mysqli Errors.


phpSensei

Recommended Posts

Hi there,

 

I fail to see why mysqli_report doesn't turn off internal errors. The only thing turning off the errors is error_reporting, or maybe I am not seeing something here.

 

At the moment, this is what's working.

 

    <?php
    mysqli_report(MYSQLI_REPORT_OFF); // Has no effect on the error output
    error_reporting(E_STRICT);
    class Valley_Mysqli extends mysqli{
            public function __construct($V_Host,$V_User,$V_Pass,$V_Name){
            parent::__construct($V_Host,$V_User,$V_Pass,$V_Name);

                            try{
                                if(mysqli_connect_errno()){ 
                                    throw new Valley_Error('Mysqli Cannot Connect',mysqli_connect_errno());
                                }
                            }catch(Valley_Error $e){
                                    print $e->getMessage();
                            }
            }
    }
    class Valley_Error extends Exception {
         public function __construct($mysqli_error_msg, $mysqli_error_code = 0, Exception $previous = null) {
            // assigned values properly
            parent::__construct('Mysqli Error Msg: '.$mysqli_error_msg, $mysqli_error_code , $previous);
        }
    }

## Testing
$db = new Valley_Mysqli('localhost','root','','valley');
    ?>

 

 

MYSQLI_REPORT_OFF Turns reporting off 
MYSQLI_REPORT_ERROR Report errors from mysqli function calls 
MYSQLI_REPORT_STRICT Throw mysqli_sql_exception for errors instead of warnings  
MYSQLI_REPORT_INDEX Report if no index or bad index was used in a query 
MYSQLI_REPORT_ALL Set all options (report all) 

Link to comment
https://forums.phpfreaks.com/topic/244289-handling-mysqli-errors/
Share on other sites

I guess the connection's error isn't controlled by mysqli itself?

 

However, From the manual:

mysqli_report() is a powerful function to improve your queries and code during development and testing phase. Depending on the flags it reports errors from mysqli function calls or queries which don't use an index (or use a bad index). 

From the comments in the manual, maybe this is some help?

Be very careful using this function - it's a per-process setting.

If your server is set up to reuse a single PHP process for multiple requests, that means the last setting of this function in any script will affect all other scripts using mysqli.

To be safe always call <? mysqli_report(MYSQLI_REPORT_OFF) ?> at the end of a script. The CGI version of PHP is probably safe from this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.