简体   繁体   中英

Laravel 8: query builder escapes the "greater than" operator

I'm getting a MySQL error when trying to run a query through Eloquent.

FlightController.php:

$flightsToFinish = SrteFlight::whereRaw('DATEDIFF(MINUTE, NOW(), disc_time) > 15')->get();
foreach ($flightsToFinish as $flightToFinish)
{
    $flightToFinish->status = 1;
    $flightToFinish->save();
} 

Error:

Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation:
1582 Incorrect parameter count in the call to native function 'DATEDIFF' (SQL: select * from 
`srte_flights` where DATEDIFF(MINUTE, NOW(), disc_time) > 15) in file
/var/www/vhosts/ar.ivao.aero/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 671

Am I missing something? Thanks in advance.

DATEDIFF just take 2 argument. (I think you misused SQL server syntax instead of MySQL syntax)

duplicate : Incorrect parameter count in the call to native function 'DATEDIFF'

Sql Server syntax

Mysql syntax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM