php - 我可以在 codeigniter 的 $this->db->escape() 中使用 md5 散列值吗?
问题描述
当我尝试在 $this->db->escape() 中使用 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->escape() 中删除单引号。
$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());
推荐阅读
- c# - C# CustomButton 不起作用 CancelButton 和 AcceptButton
- python - 如何在 Python 中将一组字符串拆分为子字符串,使较短的子字符串更有可能?
- wordpress - 从 wordpress 导出原始媒体文件
- jmeter - 比较运行脚本的时间
- emacs - 某些基本功能在 org 模式下的 table.el 中不起作用?
- powershell - 如何显示 Powershell 脚本中的错误代码?
- postgresql - 如何备份模式的特定表并在其他模式上恢复
- linux - 在 Shell 中找不到命令以及正确的退出状态。如何解决这个问题?
- r - 使用 pickerInput() 过滤数据并根据 R 中的过滤数据进行绘图
- c++ - 查找循环双链表长度的算法