-1

Hello I have made a query to select certain values from the database. Unfortunately I am getting this error message: Invalid parameter number

enter image description here

The code is as followes

$vehicles = DB::select( DB::raw("
        SELECT v.id, v.brand, v.type, v.description, v.airco, v.seats, v.hourly_rent 
        FROM vehicle as v 
        WHERE v.id 
        NOT IN((SELECT v.id FROM vehicle as v INNER JOIN reservation as r on r.`vehicle_id` = v.id WHERE r.status_id in(3,4,5) 
        AND (
                (
                    (:start >= r.startdate AND :eind <= r.enddate )
                    OR
                    (:start <= r.startdate AND :eind >= r.enddate ) 
                ) 
                OR
                (
                    (:start >= r.startdate AND :start <= r.enddate)
                    OR
                    (:eind >= r.startdate AND :eind <= r.enddate)
                )
            )
        GROUP BY v.id
        ))"), 
         array(
            'start' => $startdate, 
            'eind' => $enddate
         )
    );
Reshad
  • 2,570
  • 8
  • 45
  • 86

2 Answers2

1

You can't use the same parameter name multiple times. Give each parameter its own name and bind exactly that number of parameters:

$vehicles = DB::select( DB::raw("
        SELECT v.id, v.brand, v.type, v.description, v.airco, v.seats, v.hourly_rent 
        FROM vehicle as v 
        WHERE v.id 
        NOT IN((SELECT v.id FROM vehicle as v INNER JOIN reservation as r on r.`vehicle_id` = v.id WHERE r.status_id in(3,4,5) 
        AND (
                (
                    (:starta >= r.startdate AND :einda <= r.enddate )
                    OR
                    (:startb <= r.startdate AND :eindb >= r.enddate ) 
                ) 
                OR
                (
                    (:startc >= r.startdate AND :startd <= r.enddate)
                    OR
                    (:eindc >= r.startdate AND :eindd <= r.enddate)
                )
            )
        GROUP BY v.id
        ))"), 
         array(
            'starta' => $startdate, 
            'einda' => $enddate,
            'startb' => $startdate, 
            'eindb' => $enddate,
            'startc' => $startdate, 
            'eindc' => $enddate,
            'startd' => $startdate, 
            'eindd' => $enddate
         )
    );
Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
0

You actually can. Just leave PDO in emulation mode.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345