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
    19,408
    There's always:
    PHP Code:
    ini_set('display_errors'false); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  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
    19,408
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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