<?php
// Forum Configuration
define('DB_HOST','localhost'); // Database Hostname
define('DB_USER','root'); // Database Username
define('DB_PASSWORD',''); // Database Password
define('DB_NAME','ultraforum'); // Database Name
define('WEB_NAME','Website Name'); // Website Name
define('WEB_TITLE','Website Title'); // Website Title
// Do not modify anything under this line :)
class db {
var $dbhost;
var $dbuser;
var $dbpassword;
var $dbname;
var $query;
function connect() {
$this->db =
new mysqli($this->dbhost, $this->dbuser, $this->dbpassword, $this->dbname);
}
function __construct() {
$this->dbhost = DB_HOST;
$this->dbuser = DB_USER;
$this->dbpassword = DB_PASSWORD;
$this->dbname = DB_NAME;
}
}
我的论坛类扩展了数据库
class forum extends db{
public function __construct() {
parent::__construct();
}
function displayInfo () {
$this->forumInfo =
$getInfo = $db->db->query("SELECT * FROM threads");
while($getI = $getInfo->fetch_object()) {
return $getI->Title;
}
}
}
对于第二堂课,我想从我的 mysqli 数据库中获取所有线程。我从头等舱扩展了它,因为我想要连接信息。这就是我实现类的方式:
$ThreadInfo = new forum;
$ThreadInfo->displayInfo();
但我明白了
注意:未定义的属性:第 42 行的 forum::$db
致命错误:第 42 行对非对象调用成员函数 query()