热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Bind_param非对象错误w/mysqli。-Bind_paramNon-ObjectErrorw/mysqli

Whenattemptingtoinserttheinitialrowforatablethatwilltrackdailyviews,Iamgettingthe

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

致命错误:在/…/函数中的非对象上调用成员函数bind_param()。php在第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."
".$views."
".$title."
".$format; $stmt->bind_param("dsss", $views, $title, $format, "success"); /* execute query */ $stmt->execute(); /* close statement */ $stmt->close(); } }

1 个解决方案

#1


3  

The problem was user error: I had the name of the result column wrong.

问题是用户错误:我把结果列的名字写错了。

This was uncovered when I added echo $mysqli->error; after the line $stmt = $mysqli->prepare($sqlquery); which revealed the column-name error.

这是在添加echo mysqli->错误时发现的;行后$stmt = $mysqli->prepare($sqlquery);显示了列名错误。


推荐阅读
author-avatar
万世一统_425
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有