我有这个代码片段:
$conn = mysql_connect($host, $usr, $pwd);
当 MySQL 访问被拒绝时,如何防止 PHP 打印错误消息?
我正是需要这种语法,但对我没有任何作用。
我尝试$conn = mysql_connect($host, $usr, $pwd) or false;
了$conn = mysql_connect($host, $usr, $pwd) || false;
以下内容:
try {
$conn = mysql_connect($host, $usr, $pwd);
if(!$conn) {
throw new Exception('Failed');
}
} catch(Exception $e) {
// ...
}
PHP 总是打印连接失败的错误消息。但我只想返回 false,如果它失败了。