带有mysqli的Bind_param非对象错误

时间:2010-08-21 23:58:23

标签: php mysql mysqli sqlbindparameter

尝试插入将跟踪每日视图的表的初始行时,我收到错误:

  

致命错误:在第 157行 /.../ functions.php 中的非对象上调用成员函数bind_param()

该行是以下组中的最后一行:

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, $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();
 }
}

1 个答案:

答案 0 :(得分:3)

问题是用户错误:我的result列名称错误。

当我在显示列名错误的行echo $mysqli->error;之后添加$stmt = $mysqli->prepare($sqlquery);时,发现了这一点。