执行此功能时,我有"在非对象上调用成员函数prepare()" :
function getUserInfo() {
global $db;
$sql = $db->prepare('SELECT u.id, u.active, u.date, u.last_modified, u.username, u.country,
u.gender, u.birthday, u.avatar
FROM session s
INNER JOIN users u
ON s.sid = :sid
AND s.userid = u.id ');
$sql->execute( array(':sid' => session_id()) );
$userdata = $sql->fetch(PDO::FETCH_ASSOC);
if (empty($userdata)) {
$userdata = FALSE;
}
return $userdata;
}
答案 0 :(得分:0)
$ db尚未初始化。例如(DB_ *常量替换为您的值):
$db = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
将它放在您的代码中,您将看到$ db不是对象:
var_dump($db);