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
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). 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.