【问题标题】:Laravel query fails but works in MysqlLaravel 查询失败但在 Mysql 中有效
【发布时间】:2019-11-03 13:43:50
【问题描述】:

我是 Laravel 新手,使用以下查询,

    DB::table("rates as rate")
            ->select("rate.category")
            ->where(DB::Raw("STR_TO_DATE(CONCAT( start_day, '/', start_month, '/', start_year ) ,'%d/%m/%Y' )"), ">=", '"'.$InFormat.'"')
            ->where(DB::Raw("STR_TO_DATE(CONCAT( end_day, '/', end_month, '/', end_year ) ,'%d/%m/%Y' )"), "<=", '"'.$OutFormat.'"')            
            ->where("rate.name", "=", $name)
            ->whereNull("rate.deleted_at")->get();

这个查询没有在 Laravel 中运行但是当我使用 DB::getQueryLog() 时,获取查询并在 mysql 中运行,它工作正常。

我认为日期是问题所在。请帮帮我。

问候, 雷卡

【问题讨论】:

  • 输出什么错误?
  • "This query not running" 那么你必须有日志告诉你为什么?

标签: mysql laravel date


【解决方案1】:

我认为这是因为您的配置数据库的strict modetrue。将字段设为false

你会发现它在

config/database.php > connections > mysql > strict

【讨论】:

  • 你为什么这么认为?问题中没有提供错误消息,那么您如何确定?
  • 严格模式只设置为false。但返回空数组。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-20
  • 1970-01-01
相关资源
最近更新 更多