0

Is any way to call new mysqli($host, $user, $pass, $db_name) without printing the following errors?

Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'user'@'127.0.0.1' (using password: YES) in...

I don't like to ignore errors (@ or error_reporting(0)), i would like any other "better practice" way.

Miawa
  • 282
  • 1
  • 4
  • 10
  • 2
    I don't understand.. you don't want to see an error saying your access to the database is denied?? A better practice would be to write the code so that no warning is printed – Sterling Archer Jul 14 '13 at 18:22
  • I would imagine that you are trying to check if a connection can be made, and if not, load the page another way instead, but the warning gets in the way. Am I correct? – 3ventic Jul 14 '13 at 18:26
  • +1 for "I don't like to ignore errors" – Your Common Sense Jul 14 '13 at 18:37
  • @3ventic That is a solution, check if the connection is possible before trying to connect, if possible then connect, if not get the error it would give (Ex.: Wrong password) and send it to my error handler. But never print it. – Miawa Jul 14 '13 at 18:40
  • @YourCommonSense Thanks i think it is a Best Practice. – Miawa Jul 14 '13 at 18:41

1 Answers1

0

Well if you don't want errors to be printed - just tell PHP not to print them.
Configure PHP this way:

display_errors = 0
log_errors = 1

if you want to catch errors in some handler, you have to register it first.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345