您好我已经进行了查询以从数据库中选择某些值。不幸的是我收到此错误消息:参数号无效
代码如下:
$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
)
);
答案 0 :(得分:1)
您不能多次使用相同的参数名称。为每个参数指定自己的名称并精确绑定参数数量:
$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
)
);
答案 1 :(得分:0)
你真的可以。只需将PDO置于仿真模式即可。