【问题标题】:can i use md5 hashed values inside $this->db->escape() in codeigniter,我可以在 codeigniter 的 $this->db->e​​scape() 中使用 md5 散列值吗?
【发布时间】:2020-09-20 08:32:11
【问题描述】:

当我尝试在 $this->db->e​​scape() 中使用 md5 哈希值时,当我尝试获取结果计数时出现如下错误 "在 bool 上调用成员函数 num_rows()"

我的代码

$hashedUniqueId= md5($uniqueId);
$query = "select * from my_table where uId_hash= '".$this->db->escape($hashedUniqueId)."' AND password= '".$this->db->escape($password)."' ";
$result = $this->db->query($query);
print_r($result->num_rows());

【问题讨论】:

  • 你好卡西,欢迎来到社区。据我所知,从语法角度来看,查询看起来不错(尽管我不确定列名和表名)。我排除了md5()与错误的关系,因为md5()的输出已经是一个字符串,所以这里没有错。错误一定是别的,你能提供更多的代码和你的表格字段吗?
  • @EyadMohammedOsama 问题是,当我删除这个 $this->db->e​​scape() 并运行 $query = "select * from my_table where uId_hash= '".$hashedUniqueId 之类的查询时。 "' AND 密码= '".$password."' ";这是它的工作。

标签: php sql codeigniter


【解决方案1】:

在我看来,您正在进行双重转义。从 $this->db->e​​scape() 中删除单引号。

$query = "select * from my_table where uId_hash= ".$this->db->escape($hashedUniqueId)." AND password= ".$this->db->escape($password);

或者更好的方法是在 $this->db->query($query); 中设置变量 这样codeigniter就会为你转义。

$hashedUniqueId= md5( $uniqueId );
$query = "select * from my_table where uId_hash= ? AND password= ?";
$result = $this->db->query( $query, array( $hashedUniqueId, $password ) );
print_r($result->num_rows());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-10
    • 2015-03-07
    • 1970-01-01
    • 2013-03-24
    • 2016-07-14
    • 2016-09-19
    • 1970-01-01
    相关资源
    最近更新 更多