![]() |
Preventing mysqli errors from showing
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2003): Can't connect to MySQL server on 'mysql7.......' (111) in /home/....t/defaults/co.php on line 8
and Warning: mysqli_query() [function.mysqli-query]: Couldn't fetch mysqli in /home/..../co.php on line 18 Anyway how i can prevent these errors from showing up my on my site? In my file (co.php), i have this: PHP Code:
PHP Code:
|
I have a custom error handler setup for my sites. When it is in development it will show the error in full, but when the site is live it displays a "gentle" message (or none at all if you wish), and instead it sends an email alerting me to the fact that an error occured.
Take a look at this thread: http://www.talkphp.com/absolute-begi...html#post24193 There is a little bit more to it than what you can see there, but if this is the kind of thing you are looking for give me a nod and I will post the full code for you. |
I still dont understand it that much. If i remember correctly, php exceptions have do not work well with catching mysql errors
|
Thats because its not throwing an exception, its producing a warning.
This may be of some use to you: http://uk.php.net/set_error_handler as an alternative, on the production you may want to run with : PHP Code:
|
You can suppress errors, although it's not recommended, by adding an
@ symbol in front of the function:php Code:
The better way is to, as Hightowers suggested, set up different modes of error displaying for different users. For yourself, the developer, you want to see these warnings, but users don't. To not show warnings you can do: php Code:
Note to self: Type quicker next time so that sketchMedia doesn't beat me to it. Git! |
Quote:
A good point in your post: Quote:
|
Yeah, plus from what I hear it slows down your script.
|
Yes, i believe its because internally it converts this:
e.g. PHP Code:
PHP Code:
|
| All times are GMT. The time now is 11:22 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0