mysql - Function Dependancy PHP -
so in php im trying public variable in database class connects database when class created. -
<?php class database { public $_link; public function __construct (){ $this->_link = new pdo("mysql:host=localhost; dbname=swinkidc_student", "swinkidc_student", ""); } }
and...
<?php class user{ private $db; public function __construct() { $this->db = new database; } /** * returns id of user. * @param string $user * @return mixed */ public function getuserid($user){ $query = $_link->prepare("select `user_id` `users` `username` = :user"); $query->bindparam(":user", $user); $query->execute(); $result = $query->fetch(pdo::fetch_assoc); return $result['user_id']; } /** * checks if given user active. * @param string $user * @return bool returns true/false if user active. */ public function isuseractive($user){ } }
if extened database in user can refer _link if make private , work, however, don't think should inherit getting that..
whenever try : fatal error: call member function prepare() on non-object in /home/swinkidc/public_html/studentreach/core/authentication/user.php on line 18
as said, if try inheritance way work, don't feel thats great way of doing this.
any suggestions please?
thanks!
link
property of database
, not property of user
. therefore use:
$query = $this->db->_link->...
Comments
Post a Comment