gpt4 book ai didi

php - 使用 DB::select 执行查询的 Laravel 5 问题

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

我有一个在 phpmyadmin sql 中完美运行的查询,但是当我尝试在 laravel 5 DB::select 中运行查询时,它给我一个错误代码:

public function getCheckDueCurrentMonth()
{
$query = "SELECT * FROM history_card WHERE DUE_CAP_CHECK_DATE BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 30 DAY) WHERE MAX(HISTORY_ID) GROUP BY SERIAL_NUMBER ORDER BY DUE_CAP_CHECK_DATE DESC";

$results = DB::select( DB::raw($query));
return $results;


}

这里是错误:

QueryException in Connection.php line 761:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL
syntax;
check the manual that corresponds to your MariaDB server version for the right syntax to
use near
'WHERE MAX(HISTORY_ID) GROUP BY SERIAL_NUMBER ORDER BY DUE_CAP_CHECK_DATE DESC)'
at line 1 (SQL: (SELECT * FROM history_card WHERE DUE_CAP_CHECK_DATE BETWEEN NOW()
AND DATE_ADD(NOW(), INTERVAL 30 DAY) WHERE MAX(HISTORY_ID)
GROUP BY SERIAL_NUMBER ORDER BY DUE_CAP_CHECK_DATE DESC))

最佳答案

使用这个

public function getCheckDueCurrentMonth()
{
$query = "SELECT * FROM history_card WHERE DUE_CAP_CHECK_DATE BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 30 DAY) WHERE MAX(HISTORY_ID) GROUP BY SERIAL_NUMBER ORDER BY DUE_CAP_CHECK_DATE DESC";

$results = DB::Raw($query);
return $results;


}

关于php - 使用 DB::select 执行查询的 Laravel 5 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40022862/

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