How to suppress error messages when using 'new mysqli(...)'
| From: | Richard Morris | Date: | Fri, 05 Jan 2007 18:29:10 +0000 |
| Subject: | How to suppress error messages when using 'new mysqli(...)' | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-246621@lists.php.net to get a copy of this message | ||
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@hddbroker.com
Web Site: www.hddbroker.com