Results 1 to 5 of 5

Thread: [RESOLVED] MySQL Error Trapping

  1. #1

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Resolved [RESOLVED] MySQL Error Trapping

    Hi there,

    The last two hours I've been fiddling around trying to build a script for MySQL error trapping.
    The problem particularly is mysql_select_db where I can't catch the error.

    What I have at the moment:
    PHP Code:
        function db_select($dbame){
            
    $res = @mysql_select_db($dbname$conn);
             if (
    mysql_errno() > 0) {
                
    $host  $_SERVER['HTTP_HOST'];
                
    $uri   rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
                
    $extra 'error.php?code=6002&from='.$_SERVER['PHP_SELF'];
                
    header("Location: http://$host$uri/$extra");
            }       
        } 
    It doesn't give an error if a incorrect table name is used.
    The question is:
    Am I expecting php to give an error while it shouldn't or is there something wrong with the code?

    By the way, if someone has a better redirection script, I would appreciate it.
    Delete it. They just clutter threads anyway.

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: MySQL Error Trapping

    Your problem is the "@" in front of @mysql_select_db - this is a special character that suppresses errors from functions! Take it out and you should get an error as expected.

  3. #3

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: MySQL Error Trapping

    Quote Originally Posted by SambaNeko View Post
    Your problem is the "@" in front of @mysql_select_db - this is a special character that suppresses errors from functions! Take it out and you should get an error as expected.
    No, the '@' is to stop php from generating an error message, so you can make your own. It still should fire an error internally.
    Delete it. They just clutter threads anyway.

  4. #4

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: MySQL Error Trapping

    Found it... Huge typo in the function parameter
    Code:
    function db_select($dbname){
    Working function:
    PHP Code:
        function db_select($dbname){
            
    $res = @mysql_select_db($dbname);
             if (
    $res == false) {
                
    $host  $_SERVER['HTTP_HOST'];
                
    $uri   rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
                
    $extra 'error.php?code=6002&from='.$_SERVER['PHP_SELF'];
                
    header("Location: http://$host$uri/$extra");
            }       
        } 
    Delete it. They just clutter threads anyway.

  5. #5
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: MySQL Error Trapping

    Quote Originally Posted by TheBigB View Post
    No, the '@' is to stop php from generating an error message, so you can make your own. It still should fire an error internally.
    Yes, right, or else why would you be writing your own error handling? Duh.

    Sorry for my big fat dumb.

Posting Permissions

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



Click Here to Expand Forum to Full Width