答案 0 :(得分:2)
注射它:
class general{
public function __construct(db $db){
$this->db = $db;
}
public function userId($nickname) {
$result = $this->db->query('SELECT `id` FROM `users` WHERE `username` = $nickname'); //there i want to call to db class
return($this->db->fetch($result));
}
}
后来:
$db = new db();
$general = new general($db);