我有以下内容,但是我无法访问初始 db 类之外的数据库函数?
谢谢!
数据库.php
class db
{
private $connection;
public function __construct()
{
$this->connection = new PDO();
}
}
管理员.php
class admin
{
private $connection
public function __construct(db $connection)
{
$this->connection = $connection;
}
function myFunc()
{
// How do I access the connection here?
}
}
主文件
//include db.php
//include admin.php
$connection = new db();
$admin = new admin($connection);
// How do I access the DB here?