【问题标题】:Is it a bug in Mysqli - partial result它是 Mysqli 中的错误吗 - 部分结果
【发布时间】:2018-12-27 13:18:55
【问题描述】:

执行时的mysqli准备语句只返回部分结果,即。在 fetch() $hash,$type 上保持它们的值但 $userId 保持为空,这个问题只出现在准备好的语句中。

if($statement=$this->db->prepare("SELECT `id`,`password`,`type` FROM `login` WHERE `username`=?")){
   $statement->bind_param("s",$username);
   if($statement->execute()){
     $statement->bind_result($userId,$hash,$type);
     if($statement->fetch()){
       if(password_verify($password, $hash)){
         $this->userId=$userId;
         if($type=='u')
            return true;
       }else {
         $this->error(11);
       }
     }else
       $this->error(5);
   }else
    $this->error(4);
 }else
   $this->error(3);

【问题讨论】:

    标签: php mysql mysqli


    【解决方案1】:

    我通过将 id 转换为 CHAR 解决了这个问题

    SELECT CAST(`id` AS CHAR),`password`,`type` FROM `login` WHERE `username`=?
    

    但仍然不确定它为什么会发生。用 mysqli 猜它的 bug。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-07
      • 1970-01-01
      • 2020-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多