Mysql
 sql >> Database >  >> RDS >> Mysql

Laravel - Numero parametro non valido:parametro non definito

La tua query non riesce perché stai riutilizzando i parametri nella tua query. Laravel utilizza PDO per le sue query SQL. Secondo i documenti :

Quindi, anche se hanno lo stesso valore, dovrai rinominare quei parametri.

$results = \DB::select('SELECT client_id,
                           date_format(start_date,"%d/%m/%Y") as start_date,
                           date_format(end_date,"%d/%m/%Y") as end_date,
                           first_name, last_name, phone, postcode
                        FROM hire INNER JOIN client ON client.id = hire.client_id
                        where ((:sdate between start_date and end_date OR :edate between start_date and end_date) OR (:sdate2 <= start_date and end_date <= :edate2)) AND car_id = :car_id', [
    'sdate'  => $start_date,
    'sdate2'  => $start_date,
    'edate'  => $end_date,
    'edate2'  => $end_date,
    'car_id' => $car_id
]
);