How about something like this..
 
function runquery($query)
{
     $query = mysql_query($query);
     if (mysql_error())
     {
         echo "<div style=\"color:red\">MySQL Error: ". mysql_error() ."</div>\n";
         exit(1);
     }
     
    return $query;
}
     

        -----Original Message----- 
        From: Jeff Lewis [mailto:[EMAIL PROTECTED]] 
        Sent: Sat 1/4/2003 6:43 PM 
        To: [EMAIL PROTECTED] 
        Cc: 
        Subject: [PHP] Function to catch all mySQL errors?
        
        

        I know that mySQL errors are caught in mysql_error() and I find that
        function extremely useful (kudos!). However, I have several queries in a few
        scripts of mine but am wondering if anyone has written a small function that
        catches errors and outputs them. What I mean is lets say I have a block of
        code like so:
        
        $result = mysql_query("SELECT field1, field2 FROM users WHERE userLogin =
        '$authusername' AND userPassword = '$authpassword'");
        
        Instead of a small loop under my query that is like so:
        
        if (mysql_error()) {
         echo "Error: ".mysql_error();
         exit;
        }
        
        I'd like to be able to call a function that does this instead of adding this
        if statement after all my queries...so...anyone do something similar?
        
        Jeff
        
        
        
        --
        PHP General Mailing List (http://www.php.net/)
        To unsubscribe, visit: http://www.php.net/unsub.php
        
        



Reply via email to