I have this piece of code:
$conn = mysql_connect($host, $usr, $pwd);
How can I prevent PHP from printing an error message when access to MySQL is denied?
I need exactly this syntax, but nothing works for me.
I tried $conn = mysql_connect($host, $usr, $pwd) or false;
and $conn = mysql_connect($host, $usr, $pwd) || false;
$conn = mysql_connect($host, $usr, $pwd) || false;
and the following:
try { $conn = mysql_connect($host, $usr, $pwd); if(!$conn) { throw new Exception('Failed'); } } catch(Exception $e) {
PHP always prints an error message that the connection failed. But I just want to return false if this fails.
source share