簡體   English   中英

不能使用CodeIgniter的LIKE()

[英]Can't use CodeIgniter's LIKE()

由於某些錯誤或缺乏對ODBC連接的了解,我無法使用CodeIgniter的

$this->db->like();

(如果您真的想知道為什么我不能使用它,請在此處查看我的其他主題。)

我該如何更換

$this->db->like("name", 'a', 'after');

與其他一些安全代碼?

編輯:

顯然,我的描述不清楚。

我知道如何使用“ like()”。 我的問題是,由於其他情況,我無法使用它。 我需要的是“ like()”的替代品。

我知道我可以這樣做:

$this->db->where("name LIKE 'a%'", NULL, FALSE);

但這並不安全。

編輯2:

也許這可以工作:

$user_input = "a";

//Escape input
$escaped_input = $this->db->escape($user_input);

//add a %-sign to the end of the escaped input
$like_input = substr_replace($escaped_input, "%", -1, 0)

$this->db->where("name LIKE " . $like_input, NULL, FALSE);

但是我感覺到它不會阻止SQL注入。

有3種方法可以遵循。

  1.  $this->db->like('name', 'a', 'after'); // Output: WHERE name LIKE 'a%' 
  2. 之前

     $this->db->like('name', 'a', 'before'); // Output: WHERE name LIKE '%a' 
  3.  $this->db->like('name', 'a', 'both'); // Output: WHERE name LIKE '%a%' 

檢查數據庫連接和數據庫庫是否已加載

$this->db->like()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM