gpt4 book ai didi

php - 摆脱日期codeigniter中的单引号

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

您好,我在使用 CodeIgniter 中的查询生成器时遇到问题。问题是它使用单引号将日期括起来。查询如下所示:

SELECT *
FROM `enquiries`
WHERE DAY(enquiry_date) = 'DAY(CURDATE())'
AND YEAR(enquiry_date) = 'YEAR(CURDATE())'
AND MONTH(enquiry_date) = 'MONTH(CURDATE())'

当然,由于单引号,它永远不会返回任何结果。有什么办法可以摆脱它们吗?还是我必须执行硬编码查询?

如果我像这样从 phpmyadmin sql 控制台执行相同的查询

SELECT * FROM `enquiries` WHERE DAY(enquiry_date) = DAY(CURDATE()) AND MONTH(enquiry_date) = MONTH(CURDATE()) AND YEAR(enquiry_date) = YEAR(CURDATE())

它工作正常。

我的方法:

public function enquiries_get(){
$this->load->model('Model_enquiries');
$enquiries = $this->Model_enquiries->get_many_by(array('DAY(enquiry_date)' => 'DAY(CURDATE())', 'YEAR(enquiry_date)' => 'YEAR(CURDATE())', 'MONTH(enquiry_date)' => 'MONTH(CURDATE())' ));
if ($enquiries) {
$this->response(array('status' => 'success', 'status_code' => '200', 'message' => '200 OK', 'response' => $enquiries));
} else {
$this->response(array('status' => 'failure', 'status_code' => '404', 'message' => '404 Not Found', 'response' => 'We couldn\'t find any enquiries for today. Please check again later.'), REST_Controller::HTTP_NOT_FOUND);
}

}

有什么想法吗?

最佳答案

你可以尝试使用 php 函数来获取今天的日期、年份和月份......

$year = date('Y');
$month = date('m');
$day = date('D');

并直接在查询中传递变量...!!

关于php - 摆脱日期codeigniter中的单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37708949/

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