$this-db->query()有mysql注入保护吗?我之所以想知道,是因为我在实例中使用了它,并且没有做任何事情来防止sql注入。
发布于 2012-10-14 04:52:00
使用CodeIgniter进行查询的ActiveRecord风格可以转义参数,但不能使用query()。
您可以通过以下方式使用活动记录:
$someAge = 25;
$this->db->select('names, age');
$query = $this->db->get_where('people', array('age' => '>' . $someAge));点击此处了解更多信息:https://www.codeigniter.com/userguide2/database/active_record.html
发布于 2012-10-14 05:30:36
不,默认情况下,db->query()不是SQL注入保护,您有几个选项。使用查询绑定
$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
$this->db->query($sql, array(3, 'live', 'Rick'));对于需要构建查询的更复杂的问题,可以使用compile_bind()来获取SQL块。
$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
$safe_sql = $this->db->compile_bind($sql, array(3, 'live', 'Rick'));等。
或者在参数上使用escape $this->db->escape()
$sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")";最好的做法是首先使用表单验证,并将xss_clear、max_length等内容与上述任何一种方式结合使用。
发布于 2020-08-25 10:12:18
您可以使用query bindings。
CI 3用户指南中的示例:
$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
$this->db->query($sql, array(3, 'live', 'Rick'));https://stackoverflow.com/questions/12876763
复制相似问题