私はMysqliDb https://github.com/joshcam/PHP-MySQLi-Database-Classを持っています。私のPHPクラスの既に他のクラスからmysqliDb接続を作成しました
:
<?php
require_once ('MysqliDb.php');
class Main{
protected $db;
public function __construct()
{
$this->db = new MysqliDb ('localhost', 'root', 'tuncay', 'db');
}
}
Class A extends Main{
public function __construct()
{
$this->db = MysqliDb::getInstance();
echo $this->db->where("id", 5)->getOne('test')['text'];
}
}
$a = new A();
?>
PHPのエラー:致命的なエラー:行に/.../db/index.phpにヌルに()メンバ関数を呼び出して21 ここで()関数はMysqliDb.phpに属します
どうしたのですか?メインクラスから$ this-> dbを取得しました
DB接続をAクラスにしておきたいだけです。
hmm ...前にクラスのメインをinstatiatedしていない場合、保持するDB接続はありません!たぶんあなたは 'parent :: _ construct()'をしたいでしょうか? – Jeff