使用连接自定义数据库中的错误消息
Customize error messages in the database with 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;
}
}
?>
您可以使用不同的方法
$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());
我是 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;
}
}
?>
您可以使用不同的方法
$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());