gpt4 book ai didi

mysql - Eloquent 查询生成器 whereDate 抛出错误 : Unknown column '2017-05-03 12:00:00' in 'where clause'

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

谁能告诉我这个查询有什么问题?

$orderdaytimes = OrderDayTime::whereColumn([
['date','>=',$start],
['date','<=',$end]
]) -> get();

它给我错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '2017-05-03 12:00:00' in 'where clause' (SQL: select * from order_day_times where (date >= 2017-05-03 12:00:00 and date <= 2017-05-31 12:00:00))

我直接在 DB 中对其进行了测试,结果如下:

select * from `order_day_times` where (`date` >= '2017-05-03 12:00:00' and `date` <= '2017-05-31 12:00:00') 

但是 Eloquent 会自动在查询中添加“`”? T_T

提前致谢。

最佳答案

只需将 whereColumn 替换为 where:

$orderdaytimes = OrderDayTime::where([
['date','>=',$start],
['date','<=',$end]
]) -> get();

whereColumn 方法可用于验证两列是否相等。 where 方法只是向您的查询添加一个 WHERE 子句,这就是您想要的。

https://laravel.com/docs/5.4/queries#where-clauses的最后一段:

You may also pass an array of conditions to the where function:

$users = DB::table('users')->where([ ['status', '=', '1'], ['subscribed', '<>', '1'], ])->get();

关于mysql - Eloquent 查询生成器 whereDate 抛出错误 : Unknown column '2017-05-03 12:00:00' in 'where clause' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43732994/

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