When attempting to insert the initial row for a table that will track daily views, I am getting the error:
Fatal error: Call to a member function bind_param() on a non-object in /.../functions.php on line 157
That line is the last of the following group:
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");
Any hints as to the problem?
Just in case it's an issue with the surrounding code, here is the complete function:
function updateViewCount($title, $format, $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", $title, $format, 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, title, format, results) values (?, ?, ?, ? )";
$views = 1;
}
$stmt = $mysqli->prepare($sqlquery);
/* bind parameters for markers */
echo $sqlquery."<br>".$views."<br>".$title."<br>".$format;
$stmt->bind_param("dsss", $views, $title, $format, "success");
/* execute query */
$stmt->execute();
/* close statement */
$stmt->close();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…