mysql-Bind_param非对象错误

前端之家收集整理的这篇文章主要介绍了mysql-Bind_param非对象错误 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

尝试为将跟踪每日视图的表插入初始行时,出现错误

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)行之后;揭示了列名错误.

原文链接:https://www.f2er.com/mysql/532157.html

猜你在找的MySQL相关文章