我在 Eloquent 模型中定义了一些查询范围方法,并在 Controller 中调用它们以允许 Laravel 使用
构建查询return View::make('credit_apps/view')->with('creditApps', CreditApp::ApprovalStatus()
->SalesRep()
->Submitted()
->RefReceived()
->get()
);
Illuminate返回的错误是MySQL语法错误:
Illuminate \ Database \ QueryException SQLSTATE[42000]: Syntax error
or access violation: 1064 You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near '' at line 1 (SQL: select * from `credit_apps`
where `approval_status` = 'Approved' and `sales_rep` = 'Joe Smith' and
`date_received` between '2014-04-30 00:00:00' AND '2014-05-15
00:00:00' and `date_ref_received` between '2014-04-27 00:00:00' AND
'2014-05-30 00:00:00')
然而,当我在 MySQL Workbench 中或从命令行解析查询时,它解析得很好,尽管标准没有返回任何记录,但我知道它不会。尽管如此,它是一个有效的查询,并且在 MySQL 中运行良好。
是什么导致 Laravel 抛出错误?
最佳答案
你应该尝试这样的事情:
select * from `credit_apps`
where `approval_status` = 'Approved' and `sales_rep` = 'Joe Smith'
and
(`date_received` between '2014-04-30 00:00:00' and '2014-05-15 00:00:00')
and
(`date_ref_received` between '2014-04-27 00:00:00' and '2014-05-30 00:00:00')
关于php - 在 Laravel 中查询失败,但在 MySQL 中可以正常查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23683312/