从Codigniter的LIKE()获取奇怪的查询字符串 [英] Getting weird query string from Codigniter's LIKE()
问题描述
$ this-> db-> select(cats);
$ this-> db-> from(pets);
$ this-> db-> like(name,'a','after');
然后显示:
echo $ this-> db-> get_compiled_select();
结果:
code> SELECT cats FROM pets WHERE name LIKE'a%'{escape'!'}
由于某种原因,CI在结尾添加{escape'!'}。当我尝试运行查询时,当然会产生错误。
数据库配置:
$ db ['pyramid'] = array(
'dsn'=>'pyramid',
'hostname'=>'',
'username' =>'',
'password'=>'',
'database'=>'',
'dbdriver'=>'odbc',
'dbprefix'=>'',
'pconnect'=> FALSE,
'db_debug'=> TRUE,
'cache_on'=> FALSE,
' cachedir'=>'',
'char_set'=>'WINDOWS-1252',
'dbcollat'=>',
//'dbcollat'=& utf8_general_ci',
'swap_pre'=>'',
'encrypt'=> FALSE,
'compress'=> FALSE,
'stricton'=& FALSE,
'failover'=> array(),
'save_queries'=> TRUE
);
有人知道如何解决这个问题吗?
EDIT:
如果我这样做的话,可以使用:
$ this-> db-> select(cats);
$ this-> db-> from(pets);
$ this-> db->其中(name LIKE'a%',NULL,FALSE);
但是我必须自己转义数据。
第二个编辑:
CodeIgniter似乎会根据 this 。
也许是因为它是一个Pervasive数据库。
我已经创建了一个新的线程问题如何解决问题 Try 转到odbc驱动程序的363,使用 并替换为 也许这可以帮助 I'm trying to make a simple query in Codigniter like this: And then show it: Result: For some reason CI adds {escape '!'} at the end. Which of course generates an error when I try to run the query. Database config: Does anyone know how to fix this? EDIT: It works if I do it like this: But then I'll have to escape the data myself. SECOND EDIT: It seems like CodeIgniter produces the correct query according to this. Maybe it's because it's a Pervasive database. I've creted a new thread with a question on how to get around the problem here instead. Try Go to 363 of odbc driver and find or search with and replace it with maybe this can help 这篇关于从Codigniter的LIKE()获取奇怪的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ var = $ this-> db-> select(cats) - > like(name ,'a','after') - > get(pets) - > result();
print_r($ var);
_like_escape_str
你肯定会找到一些...
$ sql。=LIKE escape_like_str($ this-> dbprefix)。%'.sprintf($ this-> _like_escape_str,$ this-> _like_escape_chr);
$ sql。=LIKE$ this-> escape_like_str($ this-> dbprefix)。%'; //或根据需要返回false
$this->db->select("cats");
$this->db->from("pets");
$this->db->like("name", 'a', 'after');
echo $this->db->get_compiled_select();
SELECT cats FROM pets WHERE name LIKE 'a%' {escape '!'}
$db['pyramid'] = array(
'dsn' => 'pyramid',
'hostname' => '',
'username' => '',
'password' => '',
'database' => '',
'dbdriver' => 'odbc',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'WINDOWS-1252',
'dbcollat' => '',
//'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$this->db->select("cats");
$this->db->from("pets");
$this->db->where("name LIKE 'a%'", NULL, FALSE);
$var = $this->db->select("cats")->like("name", 'a', 'after')->get("pets")->result();
print_r($var);
_like_escape_str
you will definitely find something... $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ";//or return false as needs