我只是將我的網站的MySQL更改爲PDO,當我嘗試在其他課程中使用PDO時遇到了一個奇怪的問題。其他課程中的PDO有什麼問題?
class Database {
private $pdo;
public function __construct() {
$this->pdo = new PDO('mysql:host=localhost;dbname=appdora;charset=utf8', 'root', 'root');
}
}
class doClass {
//Variables
private $db;
//PDO
public function __construct(Database $db) {
$this->db = $db;
}
和代碼與回報:出現以下錯誤:
Catchable fatal error: Argument 1 passed to doClass::__construct() must be an instance of Database, none given, called in .../index.php on line xx and defined in ../classes.php on line xx
代碼:
$do = new doClass();
if ($do->loginCheck()) { echo 'loginOk'; } else { 'loginError'; }
loginCheck()是笑着的功能,沒有類的作品!
你能幫我嗎,這是什麼問題? 在此先感謝!
你在哪裏inititing你'doClass'?顯示該代碼。 – Oldskool
顯示錯誤實際指向的代碼... – poke
已添加!謝謝你的幫助! – Skylineman