PHP Mysqli语句返回单行,受影响的是-1行,并且没有错误

这真令人困惑,我必须缺少一些简单的东西.我有一个查询,检查要插入的事务是否已经存在,以防止重复.这是代码

function isaDupe($portableDB, $transactArray)
{
    $ref = $transactArray["reference"];
    $date = $transactArray["qdate"];
    $time =  $transactArray["time"];

  //prints the query so I can run by hand to test
    print "SELECT `counter` FROM transactions WHERE (`reference` = '$ref' AND `qdate` = '$date' AND `time` = '$time') ";

    if ($dupeSelectStmt = $portableDB->prepare("SELECT `counter` FROM transactions WHERE (`reference` = ? AND `qdate` = ? AND `time` = ?)"))
    {
        $dupeSelectStmt->bind_param('sss',$ref, $date, $time);
        $dupeSelectStmt->bind_result($counter);
        $dupeSelectStmt->execute();

        while ($dupeSelectStmt->fetch())
        {
            break;
        }

        $numRows = $portableDB->affected_rows;

        if ($numRows > 0)
            return TRUE;
        else if ($numRows == -1)
        {
            print " ERROR: ";
            print_r($portableDB->error);
            print_r($dupeSelectStmt->error);
            return FALSE;
        }
        else
            return FALSE;
    }
}

-如果我通过同一服务器上的Workbench手动运行查询,则会返回24行.

-如果我手动准备,设置和执行语句,这是相同的.

-affected_rows返回-1

-如果我在语句上执行num_rows则相同

-Statement或MysqLi对象上没有存储错误.

-如果将打印内容放入fetch()语句中,它将打印一行数据

-如果将提取的行存储到数组中并计算结果,则为1

-我试过分别使用每个变量运行它,同样的事情.

-同一台服务器(heck,同一MysqLi对象)上的其他查询工作正常.选择,更新和插入.

解决方法:

答案是我忘记了在MysqListmt :: execute()之后调用MysqListmt :: store_result.

添加$dupSelectStmt-> store_result()后,我能够调用$dupSelectStmt-> num_rows和$portableDB-> affected_rows,它们都显示了我知道应该看到的24个字符.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...