我有以下代码来测试与本地数据库的连接 -
$database = array(
"hostname"=>'localhost',
"username"=>'root',
"password"=>'root',
"database"=>'mydb'
);
/**
*
*/
class Book
{
private $book_id;
private $dbLink;
function __construct($book_id)
{
$this->book_id=$book_id;
$this->dbLink = mysqli_connect($database['hostname'],$database['username'],$database['password'],$database['database']) or die("Error " . mysqli_error($this->dbLink));
//var_dump($this->dbLink);
}
function qBook(){
$query = "SELECT * FROM books";
var_dump($this->dbLink->query($query));
}
}//class
$book = new Book(3);
$book->qBook();
现在,问题是我确实正确获取了 dbLink 对象,但查询没有返回任何资源。但是在文件中运行相同的查询,在对象外部获取查询。仅供参考,我正在从命令行运行脚本。有什么我错过的吗?