使用连接自定义数据库中的错误消息

时间:2015-04-26 21:28:04

标签: php connection

我是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;
    }
}
?>

1 个答案:

答案 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());