jammesz Posted January 14, 2009 Share Posted January 14, 2009 I have written my own error handling function in php. function error($type, $error, $file, $line){ die('<meta http-equiv="refresh" content="0;url=error.php?t='.rawurlencode(base64_encode($type)).'&e='.rawurlencode(base64_encode($error)).'&f='.rawurlencode(base64_encode($file)).'&l='.rawurlencode(base64_encode($line)).'">'); } error_reporting(0); set_error_handler("error", E_ALL & ~E_NOTICE); mysql_connect($cfg['mysql_server'],$cfg['ysql_username'],$cfg['mysql_password']) or trigger_error("Can't connect to database server", E_USER_ERROR); mysql_select_db($cfg['mysql_database']) or trigger_error("Can't connect to database", E_USER_ERROR); (the example error is the missing "m" from the username variable passed to mysql_connect) My error function picks up this error but i want it to pick up my own personal error msg for the error first ( ...or trigger_error("Can't connect to database", E_USER_ERROR); ) before the default php one. Anyone know how to do this??? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 14, 2009 Share Posted January 14, 2009 If you're asking whether you can make your trigger_error() occur before php's "undefined index" error: Short answer: You can't Long answer: You can't. It gets to the line and sees you are referencing an undefined index. It throws an error to tell you and THEN it processes the function as something similar to this... <?php mysql_connect($cfg['mysql_server'], '', $cfg['mysql_password']); Note the empty string for the username (because that's what PHP is passing with an unset index - an empty string). For all PHP knows, an empty string could be a valid username. After the function returns false, only then is the trigger_error() function called. if that's not what you're asking, could you clarify a bit? Quote Link to comment Share on other sites More sharing options...
jammesz Posted January 14, 2009 Author Share Posted January 14, 2009 well the error it throws before my custom one is actually the same error (eg. mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO)). i just wanted to replace with mine but i think you answered my question anyway. BTW i can still filter out php's database error msg in the error() function but it's a real hassle to do it this way and i was trying to see if there was a more efficient way. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 14, 2009 Share Posted January 14, 2009 Oh, if you just want to ignore the mysql_connect() error you can do <?php @mysql_connect($cfg['mysql_server'],$cfg['ysql_username'],$cfg['mysql_password']) or trigger_error("Can't connect to database server", E_USER_ERROR); note the @ which supresses error messages. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.