【问题标题】:Determining if no rows are returned from a prepared statment确定准备好的语句是否没有返回行
【发布时间】:2013-06-11 21:27:42
【问题描述】:

我正在对我已经工作的 mysqli 查询执行准备好的语句。我遇到了if(mysqli_num_rows($result) == 0) 行的问题,因为它现在是一个字符串而不是 mysqli_result。

if($nameAvailableStmt = mysqli_prepare($link, 'SELECT name FROM usetbl1 WHERE name=? LIMIT 1'))
{
    mysqli_stmt_bind_param($nameAvailableStmt, "s", $_POST['dangerous']);
    mysqli_stmt_execute($nameAvailableStmt);
    mysqli_stmt_bind_result($nameAvailableStmt, $result);
    mysqli_stmt_fetch($nameAvailableStmt);
}
if(mysqli_num_rows($result) == 0)

【问题讨论】:

  • $result 应该是 $nameAvailableStmt
  • 应该是mysqli_num_rows($nameAvaialbleStmt)

标签: php mysqli prepared-statement


【解决方案1】:

应该是:

mysqli_stmt_store_result($nameAvailableStmt);
if(mysqli_stmt_num_rows($nameAvailableStmt) == 0)

Documentation

【讨论】:

  • 是的,就是这个意思。 $result 将只包含您正在搜索的名称。
  • 它仍然给我同样的错误,我会继续尝试并清除缓存。
  • 你需要先调用mysqli_stmt_store_result()。
  • Same ` 警告:mysqli_num_rows() 期望参数 1 是 mysqli_result,给定对象 `
  • 我知道,我昨天在答案中添加了这个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-26
  • 1970-01-01
  • 1970-01-01
  • 2011-02-02
相关资源
最近更新 更多