尝试为将跟踪每日视图的表插入初始行时,出现错误:
Fatal error: Call to a member function bind_param() on a non-object in /…/functions.PHP on line 157
该行是以下组的最后一行:
if($stats_found) {
$sqlquery = "UPDATE vid_stats SET views = ? WHERE title = ? AND format = ? AND date = ? AND results = ?";
$views++;
} else {
$sqlquery = "INSERT INTO vid_stats (views,title,format,results) values (?,?,? )";
$views = 1;
}
$stmt = $MysqLi->prepare($sqlquery);
/* bind parameters for markers */
$stmt->bind_param("dsss",$views,$title,$format,"success");
关于这个问题有什么暗示吗?
以防万一周围的代码有问题,这是完整的功能:
function updateViewCount($title,$results) {
//update view count
global $MysqLi;
$views = 0;
if ($stmt = $MysqLi->prepare("SELECT views FROM vid_stats WHERE title = ? AND format = ? AND date = ?")) {
/* bind parameters for markers */
$stmt->bind_param("ssd",date("Y-m-d"));
/* execute query */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($views);
/* fetch value */
if ($stmt->fetch()) {
$stats_found = true;
} else { $stats_found = false; }
/* close statement */
$stmt->close();
if($stats_found) {
$sqlquery = "UPDATE vid_stats SET views = ? WHERE title = ? AND format = ? AND date = ? AND results = ?";
$views++;
} else {
$sqlquery = "INSERT INTO vid_stats (views,? )";
$views = 1;
}
$stmt = $MysqLi->prepare($sqlquery);
/* bind parameters for markers */
echo $sqlquery."
".$views."
".$title."
".$format;
$stmt->bind_param("dsss","success");
/* execute query */
$stmt->execute();
/* close statement */
$stmt->close();
}
}