PHP affected_rows returns negative 1 (-1)



这很奇怪,查询执行得很好,并将数据插入到表中,但我受影响的行显示在负值,而不是1。有人知道为什么会发生这种事吗?

connect.php:

<?php
 error_reporting(0);
 $db = new mysqli('localhost', 'root', 'pass', 'db');
 ?>

这是主代码:

<?php
 include 'connect.php';
 include 'blowfish.php';
 if($_POST['email'] == true)
 {
     if($db -> connect_errno)
     {
         echo "Could not connect to the database, please try again later...";
     }
     else
     {
         $email = $_POST['email'];
         $query = "SELECT id FROM users WHERE email = ?";
         $statmnt = $db -> prepare($query);
         $statmnt-> bind_param("s",$email);
         $statmnt-> execute();
         $statmnt-> bind_result($result);
         $statmnt-> fetch();
         $statmnt-> reset();
         if($result)
         {
             $id = $result;
             $result = "";
             $randomString = generateRandomString(50); // Generate random string
             $query = "UPDATE users SET emailString = ? WHERE id =?";
             $statmnt= $db -> prepare($query);
             $statmnt-> bind_param("si",$randomString,$id);
             $statmnt-> execute();
             $statmnt-> bind_result($result);
             $statmnt-> fetch();
             $statmnt-> reset();
             $test = $db -> affected_rows;
             echo $test;
         }
         else
         {
             echo "That Email Address is not registered...";
         }
     }
 }
 else
 {
     echo "No Email received...";
 }
 ?>

$test返回"-1"

$statmnt上调用reset()close()函数之前,应该先获取affected_rows值。

相关内容

  • 没有找到相关文章

最新更新