以下是我尝试在php中开发的类,但作为php oo的初学者我收到并且错误消息我不知道如何解决。请指出错误谢谢。
class MySQLi_DB extends mysqli {
private static $_instance = null;
private function __construct($db="test",$host="localhost", $user="root", $pass="")
{
parent::__construct($host, $user, $pass, $db);
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
}
static public function getDB()
{
if(self::$_instance == null)
{
self::$_instance = new MySQLi_DB();
}
return self::$_instance;
}
public function select($sql)
{
$res = $this->query($sql);
return $res->fetch_all();
}
}
我将对象实例化如下
require_once 'MySQLi_DB.php';
$db = MySQLi_DB::getDB();
$data = $db->select("select * from cms");
,错误低于
致命错误:调用未定义的方法 mysqli_result :: fetch_all()in D:\ wamp \ www \ Driver \ MySQLi_DB.php on 第39行