调用 CodeIgniter 的having() 方法时不应用值引用
我对 Code Igniter 有条款有疑问。
我需要使用活动记录生成以下 SQL:
SELECT *
FROM A
GROUP BY A.X
HAVING A.Y = 'test'
但使用以下代码:
$this->db->select('*');
$this->db->from('A');
$this->db->group_by('A.X');
$this->db->having('A.Y','frontend');
生成:
SELECT *
FROM A
GROUP BY A.X
HAVING A.Y = test
似乎不可能转义字符串值...或者是吗?
I have a problem with Code Igniter having clause.
I need to produce the following SQL with active record:
SELECT *
FROM A
GROUP BY A.X
HAVING A.Y = 'test'
But using the following code:
$this->db->select('*');
$this->db->from('A');
$this->db->group_by('A.X');
$this->db->having('A.Y','frontend');
Produces:
SELECT *
FROM A
GROUP BY A.X
HAVING A.Y = test
And it seems impossible to escape the string value... Or is it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以如此笨拙的方式编写having子句:
Write the having clause in a such clumsy way:
我不知道您使用的是哪个版本的CodeIgniter,但问题已不再存在。
将构建一个与此类似的渲染 SQL 字符串(带有适当的引用):
having()
方法调用受保护的_wh()
方法,该方法是where() 系列方法也使用。转义/引用过程都始终在那里进行。
I don't know what version of CodeIgniter you were using, but the problem no longer exists.
Will build a rendered SQL string resembling this (with appropriate quoting):
The
having()
method calls the protected_wh()
method which thewhere()
family of methods use as well. The escaping/quoting processes are all consistently baked-in there.