尝试为将跟踪每日视图的表插入初始行时,出现错误:
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."<br>".$views."<br>".$title."<br>".$format;
$stmt->bind_param("dsss","success");
/* execute query */
$stmt->execute();
/* close statement */
$stmt->close();
}
}
最佳答案
问题是用户错误:我的结果列名称错误.
当我添加echo $mysqli-> error时,发现了这一点;在$stmt = $mysqli-> prepare($sqlquery)行之后;揭示了列名错误.
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|