Bind_param Non-Object Error w/ mysqli(带有 mysqli 的 Bind_param 非对象错误)
问题描述
尝试为将跟踪每日视图的表插入初始行时,出现错误:
When attempting to insert the initial row for a table that will track daily views, I am getting the error:
致命错误:在 157 行/.../functions.php 中的非对象上调用成员函数 bind_param()强>
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");
关于问题的任何提示?
以防万一这是周围代码的问题,这里是完整的功能:
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();
}
}
推荐答案
问题是用户错误:我把 result 列的名称弄错了.
The problem was user error: I had the name of the result column wrong.
当我在行 $stmt = $mysqli->prepare($sqlquery); 之后添加 echo $mysqli->error; 时发现了这一点,它显示列名错误.
This was uncovered when I added echo $mysqli->error; after the line $stmt = $mysqli->prepare($sqlquery); which revealed the column-name error.
这篇关于带有 mysqli 的 Bind_param 非对象错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 mysqli 的 Bind_param 非对象错误
基础教程推荐
- php中的PDF导出 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php中的foreach复选框POST 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
