View Single Post
Old 06-09-2009, 02:55 AM   #5 (permalink)
etoolbox
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default

You can do something like this:

PHP Code:
@mysql_connect("localhost""mysql_user""mysql_password");
$error mysql_error();
if(
$error) {
    
// do something, including outputting error, logging it etc
}

$mysql_query("...");
$error mysql_error();
if(
$error) {
    
// do something, including outputting error, logging it etc

But of course you're best to either wrap all mysql calls into wrapper functions which check for errors with a common error handling function so you don't have to write mysql_error() all over the place, or use one of the many database abstraction libraries which usually have some form of common error handling function that you can set up.
__________________
Chris Hope's LAMP Blog: http://www.electrictoolbox.com/

Last edited by codefreek : 06-09-2009 at 05:45 PM. Reason: PHP Tags Added :)
etoolbox is offline  
Reply With Quote