0

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.

Emilio
  • 35
  • 1
  • 1
  • 5
  • I think the character is not escaped when doing the query, only when logged. You might have an HTML logger enabled – apokryfos Nov 22 '20 at 21:33

1 Answers1

0

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

apokryfos
  • 38,771
  • 9
  • 70
  • 114