-1
所以我有這樣的功能,數據庫類:
public function sql($sql) {
$result = $this->connection->query($sql);
return $result;
}
但它返回的錯誤:
Fatal error: Uncaught Error: Using $this when not in object context
但我不明白爲什麼我會遇到這個錯誤,我在互聯網上看過人,但似乎沒有人有這個確切的問題。
這是我的全部數據庫類:
namespace Core;
require_once ("../config.php");
class DB {
public $connection;
public function __construct() {
$this->connection();
}
public function connection() {
$this->connection = new \mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($this->connection->connect_error) {
die("Database fout");
}
}
public function sql($sql) {
$result = $this->connection->query($sql);
return $result;
}
}
然後我把它像這樣:
DB::sql('SELECT * FROM `users`');
但後來我得到的錯誤。 :/
感嘆。什麼'DB :: sql'表達?它是一個類方法的_static_調用,它不__使用一個對象... – arkascha
噢......那有點愚蠢:/ –
使用'$ bd = new DB(); $ bd-> sql('SELECT * FROM '用戶'');' –