RE: [PHP] Function to catch all mySQL errors?

From: Date: Sun, 05 Jan 2003 02:47:40 +0000
Subject: RE: [PHP] Function to catch all mySQL errors?
Groups: php.general 
Request: Send a blank email to php-general+get-130291@lists.php.net to get a copy of this message
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:jeff@hyrum.net] Sent: Sat 1/4/2003 6:43 PM To: php-general@lists.php.net 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

« previous php.general (#130291) next »