RE: [PHP] How to suppress error messages when using 'new mysqli(...)'



Well - first I would turn off display errors and turn on log errors.
Then - well there is always the error suppressor (@) - but I personally
don't like it. You could also create a custom error handler... And I
wonder if mysqli supports exceptions...

http://www.php.net/manual/en/ref.errorfunc.php
http://www.php.net/~helly/php/ext/spl/


Respectfully,
Ligaya Turmelle
Systems Analyst
Guamcell Communications
Phone: (671)689-2377
-----Original Message-----
From: Richard Morris [mailto:richard@xxxxxxxxxxxxx]
Sent: Saturday, January 06, 2007 4:29 AM
To: php-general@xxxxxxxxxxxxx
Subject: [PHP] How to suppress error messages when using 'new
mysqli(...)'

Hi,

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?

Here is the code I am using as a test case:

<?php
$db = null;

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

if (mysqli_connect_errno()) {
echo "Database connection error.\n\n";
exit();
}

echo "Connection successful.\n\n";
?>

This is the output I get:

PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user
'user'@'localhost' (using password: YES) in /home/richard/dbtest.php on
line 4

Warning: mysqli::mysqli(): (28000/1045): Access denied for user
'user'@'localhost' (using password: YES) in /home/richard/dbtest.php on
line 4 An error occurred while trying to connect to the database.

I was expecting this:

An error occurred while trying to connect to the database.

Is there a way to prevent the error messages from being display so that
the error can be handled in a nicer manner?

Thank you.

--
Richard Morris
HDD Broker, Inc.

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

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
.



Relevant Pages

  • Re: suppress SHIFT key
    ... To suppress the shift key bypass, you need to create a database property ... Doug Steele, Microsoft Access MVP ... Can anyone tell me how to suppress the SHIFT key bypass? ...
    (microsoft.public.access.formscoding)
  • who will you obey the internal historic scopes before Moustapha does
    ... Yani and Kareem achieved the additional parliaments in connection with educational girl. ... Some markets prefer, suppress, and plunge. ... Tell Khalid it's basic employing because of a integration. ...
    (sci.crypt)
  • Re: Use of an Access 97 database by XP and 97 users
    ... Do you mean they are using both MS-Access and a VB-code front-end. ... To suppress the later-version question whether to upgrade, ... suppressed AFTER the FIRST time you so open the database. ...
    (microsoft.public.access.conversion)
  • Re: Is it possible to insert a line break into a mergefield?
    ... What is probably required here is to suppress the blank lines in the ... want from individual fields in the database. ... necessary queries or is populating the MERGEFIELD fields with data itself ... I've used bookmarks too but can't get rid of the blank ...
    (microsoft.public.word.mailmerge.fields)
  • Re: suppress SHIFT key
    ... To suppress the shift key bypass, you need to create a database property ... Can anyone tell me how to suppress the SHIFT key bypass? ...
    (microsoft.public.access.formscoding)