|
-
Jun 13th, 2009, 03:16 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] MySQL Error Trapping
Hi there,
The last two hours I've been fiddling around trying to build a script for MySQL error trapping.
The problem particularly is mysql_select_db where I can't catch the error.
What I have at the moment:
PHP Code:
function db_select($dbame){ $res = @mysql_select_db($dbname, $conn); if (mysql_errno() > 0) { $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'error.php?code=6002&from='.$_SERVER['PHP_SELF']; header("Location: http://$host$uri/$extra"); } }
It doesn't give an error if a incorrect table name is used.
The question is:
Am I expecting php to give an error while it shouldn't or is there something wrong with the code?
By the way, if someone has a better redirection script, I would appreciate it.
Delete it. They just clutter threads anyway.
-
Jun 13th, 2009, 04:34 PM
#2
Re: MySQL Error Trapping
Your problem is the "@" in front of @mysql_select_db - this is a special character that suppresses errors from functions! Take it out and you should get an error as expected.
-
Jun 14th, 2009, 05:36 AM
#3
Thread Starter
Frenzied Member
Re: MySQL Error Trapping
 Originally Posted by SambaNeko
Your problem is the "@" in front of @mysql_select_db - this is a special character that suppresses errors from functions!  Take it out and you should get an error as expected.
No, the '@' is to stop php from generating an error message, so you can make your own. It still should fire an error internally.
Delete it. They just clutter threads anyway.
-
Jun 14th, 2009, 05:53 AM
#4
Thread Starter
Frenzied Member
Re: MySQL Error Trapping
Found it... Huge typo in the function parameter
Code:
function db_select($dbname){
Working function:
PHP Code:
function db_select($dbname){ $res = @mysql_select_db($dbname); if ($res == false) { $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'error.php?code=6002&from='.$_SERVER['PHP_SELF']; header("Location: http://$host$uri/$extra"); } }
Delete it. They just clutter threads anyway.
-
Jun 14th, 2009, 09:04 AM
#5
Re: MySQL Error Trapping
 Originally Posted by TheBigB
No, the '@' is to stop php from generating an error message, so you can make your own. It still should fire an error internally.
Yes, right, or else why would you be writing your own error handling? Duh.
Sorry for my big fat dumb.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|