从Codigniter的LIKE()获取奇怪的查询字符串 [英] Getting weird query string from Codigniter's LIKE()

查看:165
本文介绍了从Codigniter的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

  $ var = $ this-> db-> select(cats) - > like(name ,'a','after') - > get(pets) - > result(); 
print_r($ var);

转到odbc驱动程序的363,使用 _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 

也许这可以帮助


I'm trying to make a simple query in Codigniter like this:

$this->db->select("cats");
$this->db->from("pets");
$this->db->like("name", 'a', 'after');

And then show it:

echo $this->db->get_compiled_select();

Result:

SELECT cats FROM pets WHERE name LIKE 'a%' {escape '!'}

For some reason CI adds {escape '!'} at the end. Which of course generates an error when I try to run the query.

Database config:

$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
);

Does anyone know how to fix this?

EDIT:

It works if I do it like this:

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

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

$var = $this->db->select("cats")->like("name", 'a', 'after')->get("pets")->result();
print_r($var);

Go to 363 of odbc driver and find or search with _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);

and replace it with

$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ";//or return false as needs 

maybe this can help

这篇关于从Codigniter的LIKE()获取奇怪的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆