Re: How to suppress error messages when using 'new mysqli(...)'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Lynch wrote:
On Fri, January 5, 2007 4:35 pm, Jochem Maas wrote:
  
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.
    

With all the __toString and SPL array/object mumbo-jumbo going on, I
never know what's going on anymore with these things...

  
I found out that new mysqli doesn't throw an exception during it's construction.  The way I figured out how to deal with it was to do this:

$db =@ new mysqli('localhost', 'user', 'badpass', 'test');

With this in place no warning messages are displayed and then I can follow it up with a check for any errors using mysqli_connect_errno().  I was a little surprised to see it not use an exception as I thought that would be a better mechanism to know something is wrong when dealing with objects.  Either way, it was a simple fix.  I just want to thank Fernando Chure for pointing me in the right direction.

--
Richard Morris
Toll Free: (866) 960-3331
International: +1 250 474-6022
Fax: +1 250 474-6099
E-Mail: richard@xxxxxxxxxxxxx
Web Site: www.hddbroker.com

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux