gpt4 book ai didi

php - 在 codeigniter 中调用数据库日期函数

转载 作者:行者123 更新时间:2023-11-29 03:01:25 25 4
gpt4 key购买 nike

我在 code igniter active record 中使用 having 函数,但它产生了错误的结果。

$this->db->having('y', 'year('.$date.')');

产生:

`y` =  'year(2014-2-1)'

还有这个:

$this->db->having('y', 'year('.$date.')',true);

只是转义列的名称,所以它产生:

 y = year('2014-2-1')

但我想制作这个:

`y` = year('2014-2-1')

或者这个

 `y` = year(2014-2-1)

最佳答案

根据 active record您可以这样做的文档,将第三个参数传递为 FALSE,这样列将受到保护以添加反引号,您可以手动添加反引号

$this->db->having("`y` = YEAR('".$date."')",null,FALSE);

关于php - 在 codeigniter 中调用数据库日期函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23030779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com