【问题标题】:Does CodeIgniter automatically prevent SQL injection when using function like insert(), update() , where(), order_by()?CodeIgniter 在使用 insert()、update()、where()、order_by() 等函数时会自动阻止 SQL 注入吗?
【发布时间】:2017-11-06 23:03:10
【问题描述】:

注意:对于Does CodeIgniter automatically prevent SQL injection?how to avoid sql injection in codeigniter,我的问题不是重复问题,因为它询问了query() 函数。我在问像insert(), update() , where(), order_by()这样的功能?

我问的是以下类型的查询是否也会自动阻止 SQL 注入?

01.

$data = array(
        'title' => $title,
        'name' => $name,
        'date' => $date
);

$this->db->where('school', $school);
$this->db->update('mytable', $data);

02

$this->db->select('*');
$this->db->from('table_name');
$this->db->where('pro_name', $pro_name);        
$this->db->order_by($pro_type, 'desc');
$query = $this->db->get();
return $query->result_array();

假设所有变量都是 GET 或 POSTS 值。

【问题讨论】:

标签: codeigniter codeigniter-3 sql-injection


【解决方案1】:

CodeIgniter 的 Active Record 方法 https://www.codeigniter.com/userguide2/database/active_record.html 会自动为您转义查询,以防止注入。

你可以在这里https://stackoverflow.com/a/5857481/4895810找到答案

【讨论】:

    猜你喜欢
    • 2022-10-20
    • 2018-09-14
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 2017-11-11
    • 1970-01-01
    相关资源
    最近更新 更多