【发布时间】:2016-12-03 21:26:50
【问题描述】:
我有 MysqliDb https://github.com/joshcam/PHP-MySQLi-Database-Class。
在我的 php 类中:
<?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();
?>
致命错误:在第 21 行的 /.../db/index.php 中调用成员函数 where() on null where() 函数属于 MysqliDb.php
怎么了?我从主类得到 $this->db
我只是想在A类中保持DB连接并使用它。
【问题讨论】:
-
hmm...如果您之前没有设置过 Main 类,那么就没有要保留的 DB 连接!?也许你想做
parent::_construct()?
标签: php mysql class php-mysqlidb