dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Keeping MySQL Improved Errors From Displaying Without @

  1. #1
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063

    Keeping MySQL Improved Errors From Displaying Without @

    Is there a way I can keep MySQL errors from displaying without placing '@' in front of every function I call? Keep in mind that I use PHP's MySQLi extension.

    Thanks!

  2. #2
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    What errors? Mysqli never prints any out for me because I check for errors at each step before moving onto the next. For example after every query before I count rows I check if the query was succesffuly
    PHP Code:
    if( !$result ) { 
       
    error_log(date('m/d/y@H:i') .-'MySQL Error ('$db->errno .') '$db->error .' Query: '$sql .' In: '__FILE__ .' on or before line #: '__LINE__); 
       
    trigger_error('There was a problem with the database. Please try again later',E_USER_WARNING);
       break; 
    }
    if( !
    $result->num_rows ) {
       
    trigger_error('No records found matching the criteria.',E_USER_WARNING);
       break;
    }
    // begin working with result 
    Course that's just personal habit. Actually I just use trigger_error as I have a custom error handler, but that gives you an idea I hope. Keep in mind that that is within a function, so break would keep it from going to the next step. IE if the result failed, i wont try to number the rows. Also a custom error handler can output errors of certain types however you want. See the manual on error handling. http://php.net/manual/en/book.errorfunc.php Also you can turn error_reporting off or raise the threshold to limit the errors shown. Personally I am not a fan of using the @supressor.

    HTH
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,443
    There's always:
    PHP Code:
    ini_set('display_errors'false); 
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  4. #4
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063
    Does that turn off all errors? And does it just keep PHP from displaying errors by itself? If I wanted to, could I still use:

    PHP Code:
    echo $mysqli->error
    ?

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,443
    Quote Originally Posted by Joseph Witchard View Post
    Does that turn off all errors? And does it just keep PHP from displaying errors by itself? If I wanted to, could I still use:

    PHP Code:
    echo $mysqli->error
    ?
    Yes, display_errors only affects errors generated by PHP, not code you explicitly call such as that. If you have a common config file that your application uses, you might want to use it to turn on display_errors when you need to debug, then set it back to false for normal production mode, so that errors are logged instead of displayed to the user.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles