我想检查用户的在线状态,并从我读过的许多来源构建了一个页面。我仍然无法获得理想的结果。也许有人可以查看我当前的代码,让我知道这部分有什么问题?下面的代码是检查用户在线状态的代码,我当前也收到以下错误消息:
Fatal error: Call to undefined method PDOStatement::prepare() in C:\xampp\htdocs\includes\online_status.php on line 11
<?php
error_reporting(E_ALL & ~E_NOTICE);
require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconfig.php');
$timestamp = date("Y-m-d H:i:s");
#RETURN A LIST OF WHICH USERS ARE INDICATED AS ONLINE IN THE TABLE
$stmtonline = $db->prepare('SELECT * FROM sys_members');
$stmtonline->execute;
$foundRows = $stmtonline->prepare("SELECT FOUND_ROWS()")->fetchColumn();
if($foundRows->rowCount())
{
echo $foundRows->rowCount();
}
if($row_count=="0")
{
#INSERT THE USER INTO THE ONLINE_USERS TABLE IF THEY DO NOT EXIST
$stmtinsrt = $db->prepare('INSERT INTO sys_online_users (memberID, username, last_active) VALUES (:memberID, :username, :last_active)');
$stmtinsrt->execute(array(
':memberID' => $_SESSION['memberID'],
':username' => $_SESSION['username'],
':last_active' => $timestamp
));
$id = $db->lastInsertId('memberID');
}
else
{
#UPDATE THE USER'S CURRENT STATUS IN THE TABLE IF THE DO EXIST
$stmtupd = $db->prepare('INSERT INTO sys_online_users (memberID, username, last_active) VALUES (:memberID, :username, :last_active)');
$stmtupd->execute(array(
':memberID' => $_SESSION['memberID'],
':username' => $_SESSION['username'],
':last_active' => $timestamp
));
$id = $db->lastInsertId('memberID');
}
?>
答案 0 :(得分:0)
将$stmtonline->prepare
替换为$db->prepare
答案 1 :(得分:0)
我最终得到了我的查询工作,通过简化它...这是对我有用的结果:
<?php error_reporting(E_ALL & ~E_NOTICE); require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconfig.php'); $timestamp = date("Y-m-d H:i:s");
{
$stmtinsrt = $db->prepare('INSERT INTO sys_page_hit (memberID, username, last_active) VALUES (:memberID, :username, :last_active) ON DUPLICATE KEY UPDATE last_active= :last_active');
$stmtinsrt->execute(array(
':memberID' => $_SESSION['memberID'],
':username' => $_SESSION['username'],
':last_active' => $timestamp
));
$id = $db->lastInsertId('memberID');
}
&GT;