how to call to a function in another class. I can't explain, but i hope you will understand my problem.
Notice: Undefined variable: db in class general.
Inject it:
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));
}
}
And later:
$db = new db();
$general = new general($db);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.