【问题标题】:getting "mysqli num_rows Commands out of sync; you can't run this command now" error in mysql querymysql 查询中出现“mysqli num_rows 命令不同步;您现在无法运行此命令”错误
【发布时间】:2012-09-26 02:32:14
【问题描述】:

我从 php 脚本调用的 mysqli 查询有问题。我已经重写了很多次,并且不断收到错误:“mysqli num_rows 命令不同步;您现在无法运行此命令” 这是从该页面访问数据库的第一次尝试。我之前绑定了参数,然后调用: $checkAcct->num_rows() 并遇到了同样的问题。我还尝试了有人在此站点上的不同帖子中提出的建议: 做 { $checkAcct->use_result(); } 而( $checkAcct->next_result() ); 但这也不起作用,我遇到了同样的错误。在确保具有这些详细信息的用户不在数据库中后,我执行另一个查询以将用户的信息插入站点,但我收到的错误消息与此查询有关。让我知道是否也有助于查看其他查询。

下面是我尝试使用的代码:

$checkAcct = $dbConn->stmt_init();
$existingAcct = array();

if ($checkAcct->prepare("select usrName, eAddy from usr where usrName = ? OR eAddy = ?"))
{
    $checkAcct->bind_param("ss", $usr, $eml);
    $checkAcct->execute();
    $checkAcct->bind_result($result);
    while($checkAcct->fetch())
    {
        $existingAcct[] = $result;
    }
    if ($existingAcct[0] != 0)
    {

        if ($usr == $inputs['usrName'] && $eml == $inputs['eAddy'])
        {
            $acctSetupErrors[] = "Someone with your username and email address already exists. Please use the forgot password form to reset your password";     
        } else if ($eml == $inputs['eAddy'])    {
            $acctSetupErrors[] = "Someone with your email address already exists. Please use the forgot password form to reset your password or setup an account with a different email address";       
        } else {
            $acctSetupErrors[] = "Someone with your username already exists. Please choose a different username";
        }
    } 

    $checkAcct->free_result();
    $checkAcct->close();

编辑

好的。我尝试了你的方法,但它也不起作用,所以我去寻找任何以前的数据库调用。我在脚本中链接较高的包含文件中的 db 调用中发现了有问题的查询。有趣的是,它从未在其他任何地方造成问题,但现在我释放了结果并且效果很好。感谢您对此的帮助。我没有足够的分数来支持你建议它必须在代码上方的某个地方。

【问题讨论】:

  • 你可以接受答案,而不是点赞
  • 完成。我是新手。谢谢!

标签: php mysql sql mysqli


【解决方案1】:

你能像这样改变上面的代码,看看你得到了什么

$checkAcct = $dbConn->stmt_init();
$existingAcct = array();

if ($checkAcct->prepare("select usrName, eAddy from usr where usrName = ? OR eAddy = ?"))
{
    $checkAcct->bind_param("ss", $usr, $eml);
    $checkAcct->execute();
    $checkAcct->store_result();
    printf("Number of rows: %d.\n", $stmt->num_rows);
    $checkAcct->free_result();
    $checkAcct->close();
}

您能否确保在再次使用之前清除准备缓冲区。我希望在此语句之前执行的其他一些查询在 mysqli 准备语句缓冲区中仍然处于活动状态。

【讨论】:

  • 谢谢。这是一个隐藏在包含文件中的数据库调用,我没想到要检查。
猜你喜欢
  • 1970-01-01
  • 2013-08-29
  • 2012-07-19
  • 2012-12-01
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多