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

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

 



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


[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