我有一个应用程序读取它的一个类:
public function __construct()
{
global $config;
//Establish a connection to the database and get results set
$this->db = new Database("localhost",$config["dbuser"],$config["dbpass"],"student");
$this->records = $this->db->query("SELECT * FROM major") or die("ERROR: ".$this->db->error);
echo "<pre>".var_dump($this->records)."</pre>";
}
我的问题是这var_dump shows
是$this->records
一个布尔值。我已经阅读了文档,发现 SELECT 查询应该返回一个结果集。这是应用程序使用的唯一查询。
数据库类:
class Database
{
private $con;
public function __construct($server,$user,$password,$database)
{
$this->con = new mysqli($server,$user,$password,$database) or die ("FATAL ERR: ".mysqli_error());
}
public function query($qry)
{
if(!isset($this->con)) die("ERROR: YOU ARE TRYING TO QUERY BEFORE THE CONNECTION IS ESTABLISHED!");
return $this->con->query($qry) or die("FATAL ERROR:".$this->con->error);
}
}
有什么想法我哪里出错了吗?