Codeigniter 3查询生成器自动引用错误 [英] Codeigniter 3 query builder auto quote wrongly

查看:59
本文介绍了Codeigniter 3查询生成器自动引用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取下面的sql格式

I'm am trying to get the sql format below

SELECT * FROM `ci_nest` WHERE `lft` > 9 AND `rgt` < 28 AND `rgt` = `lft` + 1 ORDER BY `lft`

但是Codeigniter 3正在插入

However Codeigniter 3 is inserting the quotes at the wrong place.

我的代码如下

$this->db->where($leftcol . ' > ' . $leftval . ' AND ' . $rightcol . ' < ' . $rightval);
$this->db->where($rightcol . " = " . $leftcol . " +1");
$this->db->order_by($leftcol);
$query = $this->db->get($this->table_name);

什么是代码点火器查询输出

What codeigniter query output is

SELECT *
FROM `ci_nest`
WHERE `lft` > 9 AND `rgt` < 28
AND `rgt` = `lft` `+1`
ORDER BY `lft`

正如您在行中所看到的那样,错误地格式化了 rgt = lft + 1 3查询生成器。

As you can see at the line and rgt = lft + 1 is being formatted wrongly by codeigniter 3 query builder.

任何解决此问题的方法都将受到赞赏。

Any workaround for this issue would be appreciated.

推荐答案

通过可选的第3个参数禁用反引号,并自行创建反引号。

Disable the backticks by the optional 3rd parameter and create them by your own.

$this->db->where($rightcol, '`'.$leftcol.'`+1', FALSE);

或者用双引号似乎更好。

Or with double quotes, seems better.

$this->db->where($rightcol, "`$leftcol`+1", FALSE);

这篇关于Codeigniter 3查询生成器自动引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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