第二次调用时查询失败-PHP mysqli_error

时间:2019-05-10 04:47:43

标签: php mysqli

我有两个函数,如果我一一调用它就可以正常工作,但是当我一次调用它们时,得到了“查询失败”的查询,没有错误消息返回。

这是我的PHP代码:

config.php

<?php
    $host = "localhost";
    $user = "root";
    $pass = "root";
    $db = "TRS";

    $conn = new mysqli($host, $user, $pass, $db);
    if($conn->connect_error){
        echo "Failed:" . $conn->connect_error;
    }
?>

logic.php

    <?php
        include 'customMailSender.php';
        include '../../Model/EmailContent.php';
        include 'crud.php';

        function resetPassword($email){
           $objCRUD = new crud();  // crud operation object

           $result = $objCRUD->getUserByEmail($email);

           $token = generateRandomString();

           $objCRUD->updateTokenRecords($result["UserID"], '1', 
             $token);

           sendResetPasswordMail($result["Email"], 
               $result["FirstName"], $token);

         }

   ?>


CRUD.php类

<?php

require "../../Config/config.php";
class crud
{
    function getUserByEmail($email){
            global $conn;


           $sql_query = "CALL SP_GET_USER_BY_EMAIL('". 
            mysqli_real_escape_string( $conn ,$email) ."')";


           $result = mysqli_query($conn, $sql_query) or die("Query 
             fail: " . mysqli_error());

           // Associative array
           $row=mysqli_fetch_array($result,MYSQLI_ASSOC);

          return $row;

    }

    function  updateTokenRecords($userID, $type, $token){
          global $conn;

          $sql_query = "CALL 
      SP_RESET_USER_PASSWORD('".$userID."','".$type."','".$token."');";



          mysqli_query($conn, $sql_query) or die("Query fail: " . 
           mysqli_error());


    }


}

如果我调用'$ objCRUD-> getUserByEmail($ email)'或$ objCRUD-> updateTokenRecords($ result [“ UserID”],'1',              $ token)'。但是第二次在resetPassword()函数中都调用这两个函数会返回“查询失败:”

0 个答案:

没有答案