我是PHP新手,希望在不显示警告的情况下将自己的连接恢复为自定义消息。
但是当我添加检查时没有任何反应,我的完整代码如下。
<?php
class Connect {
private $Connect;
public function Connect() {
$this->Connection();
if(connection_aborted() == TRUE) {
$this->Connection();
}
}
public function Connection() {
global $Config;
$this->Connect = new mysqli($Config['mysql']['hostname'], $Config['mysql']['username'], $Config['mysql']['password'], $Config['mysql']['database'], $Config['mysql']['dataport']);
if($this->Connect == false){
exit('The connection fails, check config.php');
}
return false;
}
}
?>
答案 0 :(得分:0)
您可以使用不同的方法
$this->Connect = new mysqli(
$Config['mysql']['hostname'],
$Config['mysql']['username'],
$Config['mysql']['password'], $Config['mysql']['database'],
$Config['mysql']['dataport'])
or die('The connection fails, check config.php');
或
if (!$this->Connection) {
die('The connection fails, check config.php');
}
如果我是你,我也应该把错误放在骰子部分:
die('Connection failed' . mysqli_connect_error());