我有以下代码,我无法解释为什么它会输出错误。
class User extends mysqli{
// property declaration
private $server;
private $user;
private $pass;
private $database;
private $conn;
function __construct($server, $user, $pass, $database){
$mysqli = new mysqli($server, $user, $pass, $database);
if ($mysqli->connect_errno) {
echo "Connect failed: ". $mysqli->connect_error;
exit();
}
$this->conn = $mysqli;
return 0;
}
function __destruct(){
$conn = $this->conn;
$conn->close();
}
}
和主要代码
include("global_config.php");
require "User.php";
$u = new User($con['server'],$con['user'],$con['pass'],$con['db']);
$u->query("SELECT * FROM users");
返回此错误
Warning: mysqli::query() [mysqli.query]: Couldn't fetch User in E:\Xampp\htdocs\testphp\testMysql.php on line 9
通常,它应该表现得像这里的PHP 继承,使用子变量的父函数
但它没有
我已经用尽了我的想象力来思考我可以用于谷歌搜索的最可能的关键字
有任何想法吗?