我目前正在实施类似于twitter的关注系统。问题是其中一个查询似乎不起作用。
我有两个数据库; tbl_users并关注。
tbl_users包含:userId,userName,userEmail,userPass和followers_count
关注包含:follow_id,接收者,发件人和状态
在USER类中,我有以下功能:
//get all users from database where userID not = your id
public function users($user_id){
global $pdo;
$query = $pdo->prepare("SELECT * FROM `tbl_users` U LEFT JOIN `follow` F on
`f`.`receiver` = `U`.`userID` AND CASE WHEN `F`.`sender` = ? THEN
`F`.`receiver` = `U`.`userID` END where `U`.`userID` != ?");
$query->bindValue(1,$user_id);
$query->bindValue(2,$user_id);
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
在我的index.php中,我调用以下代码:
$user_home = new USER();
$user_id = $_SESSION['userID'];
$users = $user_home->users($user_id);
返回此错误:
[29-Aug-2017 05:17:05 UTC] PHP Fatal error: Uncaught Error: Call to a
member function prepare() on null in
/home/iamlive/public_html/class.channel.php:143
Stack trace:
#0 /home/iamlive/public_html/index.php(25): USER->users('1')
#1 {main} thrown in /home/iamlive/public_html/class.channel.php on line 143