所以我有2个类db和user_access类。
db class:
class db {
public function db()
{
$db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if ($db->connect_errno()) {
echo "Error: Could not connect to database.";
exit;
}
else { return $db; }
}
}
user_Access类:
class user_access{
public $db;
public function __construct($db){
$this->db = $db;
}
public function check_login($login,$password){
$password = sha1($password);
$sql = "SELECT * FROM admins WHERE username = '$login' AND password = '$password'";
$result = mysqli_query($this->db,$sql);
if($result->num_rows > 1){
echo 'ok';
}else{
echo "not";
}
}
}
我得到的错误:
注意:尝试在第24行的C:\ xampp \ htdocs \ brothers.traning \ profiadmin \ models \ login_Class.php中获取非对象的属性
任何人都可以告诉我为什么我不能在user_access类中使用mysqli?我试过了:
$result = $this->db->query($sql);
但也没有帮助。
$db = new db();
$userDB = new user_access($db->db());
$userDB->check_login('artur','ol');
我在第24行遇到错误