dpmfur2635 2014-04-24 04:24
浏览 102
已采纳

比较字段的MD5结果为NULL

I have a function to calculate which inputs MD5 of the user id and outputs the id,name

public function verifyUser($enc)
{
    //echo $enc;
    $query = $this->db->prepare("SELECT id,name FROM `users` WHERE MD5(`id`) = '$enc'");
    //$query->bindValue(1,$enc);
    $query->execute();
    $data = $query->fetch();
    //var_dump($query);
    return $data;
}

But the above query always results NULL.

eg I have a user with id=2 and MD5(2) is c81e728d9d4c2f636f067f89cc14862c. The query it generates is :

SELECT id,name FROMusersWHERE MD5(id) = 'c81e728d9d4c2f636f067f89cc14862c'

But though the user exits , it results null.

  • 写回答

1条回答 默认 最新

  • doufei3561 2014-04-24 04:53
    关注

    Query alone is working as expected. check this SQLFiddle: http://sqlfiddle.com/#!2/e262d/1

    however seems to be the following line has some issue. try this corrected one:

    $query = $this->db->prepare("SELECT id, name FROM users WHERE MD5(id) = '$enc'");
    

    note: I have removed the wrong quote character present in your code surrounding users and id.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动