Richard Lynch wrote: > On Fri, January 5, 2007 12:29 pm, Richard Morris wrote: >> I am having this problem that I hope can be worked around. I make a >> connection to our MySQL database using the object version of mysqli. >> If >> access is denied because of an incorrect username or password, mysqli >> displays an error. Is there any way to suppress the error message? > > To suppress a single error message in a single line you can use the @ > operator in PHP: > > @this_code_errors_but_youll_never_see_the_error(...); > > To catch errors in a more general manner: > http://php.net/set_error_handler > > Also, since mysqli is new-fangled, it's probably using that fancy > try/catch/throw stuff, so you could PROBABLY wrap it in a try/catch if that was the case his error would have mentioned something about an uncaught exception. as it stands I find the WARNING inappropriate - you are forced to use an @ if using this new-fangled object ALWAYS because a failed connection may occur (it's a valid but undesired program state, no?) and you have no way of checking this before the WARNING is spat out. in this case, mainly because the WARNING is being generated inside an object constructor, php/mysqli should be throwing an exception - which can be handled in a programmatically sane way ... e.g.: try { $db = new mysqli('localhost', 'user', 'badpass', 'test'); } catch (DBServerException) { echo "I'm sorry our database server seems to be sleeping"; exit; } catch (DBNotFoundException) { echo "I'm sorry our database seems to have been deleted by a digruntled ex-sysadmin"; exit; } catch (DBConnectException) { echo "I'm sorry our database doesn't like the look of you - your not coming in"; exit; } (and I seen/heard php devs state multiple times that failed object constructors should throw exceptions on failure - actually there not much else you can do given that return values are invalid from within the context of an object constructor) sidenote: where exactly do you put the @ to suppress the error in this line?: $db = new mysqli('localhost', 'user', 'badpass', 'test'); > block and that will somehow magically suppress the error message, > maybe... I really don't know (or want to know) much about this, but > you're welcome to research it and find out. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php