Function to catch all mySQL errors?

From: Date: Sun, 05 Jan 2003 02:43:29 +0000
Subject: Function to catch all mySQL errors?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-130290@lists.php.net to get a copy of this message
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

« previous php.general (#130290) next »