无法使用CodeIgniter的LIKE() [英] Can't use CodeIgniter's LIKE()
问题描述
由于某些错误或我在ODBC连接中缺乏相关知识,我无法使用CodeIgniter的
$ this-> db-> like();
(如果你真的想知道为什么我不能使用它,请参阅我的其他线程这里。)
如何替换
$ this-> db-> like(name,'a'后');
使用其他安全代码?
编辑:
很明显我的描述不清楚。
知道如何使用like()。我的问题是,我不能使用它,因为其他情况。我需要的是like()的替代品。
我知道我可以这样做:
$ this-> db->其中(name LIKE'a%',NULL,FALSE);
但不安全。
编辑2:
也许可以运作:
$ user_input =a;
//退出输入
$ escaped_input = $ this-> db-> escape($ user_input);
//将一个%-sign添加到转义输入的末尾
$ like_input = substr_replace($ escaped_input,%,-1,0)
$ b b $ this-> db-> where(name LIKE。$ like_input,NULL,FALSE);
但我得到的感觉不会阻止sql注入。
-
>之后
$ this-> db-> like('name','a'后');
//输出:WHERE name LIKE'a%'
-
之前
$ this-> db-> like('name','a','before ');
//输出:WHERE name LIKE'%a'
-
$ this-> db-> like('name','a','both ');
//输出:WHERE name LIKE'%a%'
检查您的数据库连接和加载的数据库库
$ this-> db - > like()
in Codeigniter
Because of some bug or my lack of knowledge in ODBC connections I can't use CodeIgniter's
$this->db->like();
(If you really want to know why I can't use it, see my other thread here.)
How do I replace
$this->db->like("name", 'a', 'after');
with some other safe code?
EDIT:
Obviously I wasn't clear in my description.
I KNOW how to use "like()". My problem is that i CAN'T use it because of other circumstances. What I need is a substitute for "like()".
I know I could do it like:
$this->db->where("name LIKE 'a%'", NULL, FALSE);
but that wouldn't be safe.
EDIT 2:
Maybe this could work:
$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);
But I get the feeling it would not prevent sql injections.
There is 3 methods to follow.
after
$this->db->like('name', 'a', 'after'); // Output: WHERE name LIKE 'a%'
before
$this->db->like('name', 'a', 'before'); // Output: WHERE name LIKE '%a'
both
$this->db->like('name', 'a', 'both'); // Output: WHERE name LIKE '%a%'
Check your database connection and database library loaded as well
$this->db->like()
in Codeigniter
这篇关于无法使用CodeIgniter的LIKE()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!