0

I am currently using this code to hide mysqli_connect() errors.

error_reporting(E_ALL); ini_set('display_errors',0);

But with reporting ON, when I introduce an incorrect setting into a mysqli_connect() param the usual gibberish appears. Is it possible to display a message of my own such as "Check DB connection settings" rather than the garble you usually get IF mysqli_connect() fails?

I presume this is done with try/catch. Can anyone shed some light on this with of how I might do the above?

Could be along the lines of pseudo If mysqli_connect bad settings, echo "bad settings please check".

Thanks.

  • Have you read the manual yet? There's a [`->connect_error`](http://www.php.net/mysqli.construct) to probe for. – mario Aug 17 '13 at 18:50
  • possible duplicate of [How to check if mysqli\_connect was successful or not?](http://stackoverflow.com/questions/15028757/how-to-check-if-mysqli-connect-was-successful-or-not) – mario Aug 17 '13 at 18:51
  • OK OK... Now lets bring on the downvotes shall we? –  Aug 17 '13 at 18:54

1 Answers1

0

Try this:

mysqli_connect("myhost","myuser","mypassw","mybd") or die("THIS IS THE ECHOED MESSAGE");

You can also use this:

$conn= mysqli_connect("myhost","myuser","mypassw","mybd") or die("SOME PREAMBLE: " . mysqli_error($conn));
d'alar'cop
  • 2,357
  • 1
  • 14
  • 18