我写了一个跟数据库连接的文件,我故意写错了密码,为什么不执行我的printError这个函数啊?
<?php
class MyDB {
protected $mysqli;
protected $showError;
public function _construct($configFile = "password.inc.php", $showError = TRUE) {
require ($configFile);
$this->mysqli = new mysqli ( $dbhost, $dbuser, $dbpasswd, $dbname );
// 如果连接失败,输出错误信息
if (mysqli_connect_errno ()) {
$this->showError = $showError;
$this->printError ( "连接失败,原因为:" . mysqli_connect_error () );
$this->mysqli = FALSE;
exit ();
}
}
protected function printError($errorMessage) {
if ($this->showError) {
echo '<p><font color="red">' . htmlspecialchars ( $errorMessage ) . '</font></p>';
}
}
public function close() {
if ($this->mysqli)
$this->mysqli->close ();
$this->mysqli = FALSE;
}
public function _destruct() {
$this->close ();
}
}
$aa=new MyDB();
$aa->_construct();
<?php
class MyDB {
protected $mysqli;
protected $showError;
public function _construct($configFile = "password.inc.php", $showError = TRUE) {
require ($configFile);
$this->mysqli = new mysqli ( $dbhost, $dbuser, $dbpasswd, $dbname );
// 如果连接失败,输出错误信息
if (mysqli_connect_errno ()) {
$this->showError = $showError;
$this->printError ( "连接失败,原因为:" . mysqli_connect_error () );
$this->mysqli = FALSE;
exit ();
}
}
protected function printError($errorMessage) {
if ($this->showError) {
echo '<p><font color="red">' . htmlspecialchars ( $errorMessage ) . '</font></p>';
}
}
public function close() {
if ($this->mysqli)
$this->mysqli->close ();
$this->mysqli = FALSE;
}
public function _destruct() {
$this->close ();
}
}
$aa=new MyDB();
$aa->_construct();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货