PHP- mysqli-> num_rows总是返回0,Prepared语句

时间:2017-09-05 03:32:34

标签: php mysqli sql-update prepared-statement mysql-num-rows

首先,我想告诉我,我已经走了所有重复的问题。并尝试了那里建议的变化。

目前我已尝试将num_rows更改为num_rows() 并使用store_result();并使用affected_rows()

store_result();

之后调用execute()

我认为可能还有其他一些我无法弄清楚的问题

$conn->autocommit(false);   
if ($sucess){
    $stmt2 = $conn->prepare("UPDATE e_eventqueue SET e_urlfil=? WHERE e_id=? 
AND u_id=?");
    $stmt2->bind_param("iis",$e_urlfil,$e_id,$u_id);

    if($stmt2->execute()){
         $stmt2->store_result();
        echo "true";
        echo $stmt2->num_rows;  // <- this always return 0 even when its not
        $stmt2->close();
        $conn->commit();
    }
 else{
      $conn->rollback();
     echo "rollback";
  }

}

2 个答案:

答案 0 :(得分:2)

如上面的评论中所述,请查看文档:

http://php.net/manual/mysqli-stmt.affected-rows.php

  

返回上次执行的语句

更改,删除或插入的总行数

http://php.net/manual/mysqli-stmt.num-rows.php

  

返回语句结果集中的行数

答案 1 :(得分:2)

1st:对于更新查询您需要检查<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="toggle-wrap"> <div class="course-info-toggle"> <p id="course-details-toggle-font">COURSE OBJECTIVES</p> <img src="img/course-down-arrow.png" align="course-down-arrow"> </div> <div class="toggle-content"> <p> simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled”<br> <p> simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled”<br> </p> </div> </div>。不是affected_rows

第二名执行此类检查后num_rows如果查询成功执行但数据没有变化则意味着$row_count= $stmt2->affected_rows;

return 0

Affected_rows:

Affected_rows适用于if($stmt2->execute()){ echo $stmt2->affected_rows; }

Num_rows:

Num_rows适用于insert,update,delete