我可以在 codeigniter 中的 $this->db->e​​scape() 中使用 md5 哈希值吗?

can i use md5 hashed values inside $this->db->escape() in codeigniter,

当我尝试在 $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());

如我所见,你正在双重逃避。从 $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());