TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-18-2009, 03:50 AM   #1 (permalink)
The Visitor
 
Join Date: May 2009
Posts: 2
Thanks: 0
vixxy is on a distinguished road
Default 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:
mysqli_report(MYSQLI_REPORT_OFF);
$dbcon = new mysqli($server,$user,$pass,$db); 
I have tried these various codes:
PHP Code:
if (!$dbcon) {
    die(
'Server Error');
}
if (
$dbcon->ping()) {
 die(
'Server Problem');
}
if (
mysqli_connect_error()) { die('Connect failed1'); } 
if (
mysqli_connect_errno()) { die('Connect failed2'); } 
and yet, none of them is currently able to make mysqli shut up when it cant connect
vixxy is offline  
Reply With Quote
Old 05-18-2009, 07:22 AM   #2 (permalink)
The Acquainted
 
Hightower's Avatar
 
Join Date: May 2009
Location: Durham, UK
Posts: 134
Thanks: 9
Hightower is on a distinguished road
Default

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: Exception Handling

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.
__________________
Hightower's Softpolio
Send a message via MSN to Hightower
Hightower is offline  
Reply With Quote
Old 05-18-2009, 01:13 PM   #3 (permalink)
The Visitor
 
Join Date: May 2009
Posts: 2
Thanks: 0
vixxy is on a distinguished road
Default

I still dont understand it that much. If i remember correctly, php exceptions have do not work well with catching mysql errors
vixxy is offline  
Reply With Quote
Old 05-18-2009, 01:16 PM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

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:
error_reporting(0); 
That will stop any warnings etc from being displayed.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 05-18-2009, 01:19 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

You can suppress errors, although it's not recommended, by adding an @ symbol in front of the function:

php Code:
@ping();

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:
error_reporting(0);
/* Or... */
ini_set('display_errors', 'off');

Note to self: Type quicker next time so that sketchMedia doesn't beat me to it. Git!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 05-18-2009, 01:26 PM   #6 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Note to self: Type quicker next time so that sketchMedia doesn't beat me to it. Git!


A good point in your post:
Quote:
You can suppress errors, although it's not recommended, by adding an @ symbol in front of the function:
Indeed its not recommended, having to grep through code to find those pesky things when your script is just quietly falling over is a tedious task at best!
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 05-18-2009, 02:19 PM   #7 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Yeah, plus from what I hear it slows down your script.
allworknoplay is offline  
Reply With Quote
Old 05-18-2009, 02:38 PM   #8 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Yes, i believe its because internally it converts this:

e.g.
PHP Code:
@someFunction(); 
to this:
PHP Code:
error_reporting(0);
someFunction();
error_reporting(WHATEVER IT WAS SET TO BEFORE); 
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
modifying PHP.ini allworknoplay General 3 04-27-2009 02:50 PM
Muting errors in PHP5 Ross General 4 06-30-2008 03:13 PM
Exceptions and suppressing mysqli errors delayedinsanity Advanced PHP Programming 12 05-07-2008 07:27 PM
mysqli wGEric General 7 04-06-2008 06:00 PM
mysqli OOP interface introduction Matt83 General 4 12-22-2007 11:52 PM


All times are GMT. The time now is 03:51 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design