SQLSTATE [HY093]:参数号无效 - 无法找到重复项

时间:2015-05-24 15:18:36

标签: php sql postgresql pdo

当我尝试在SQL(PHP / PDO)中运行此函数的提取部分时,我收到以下错误:

向数据库提交查询时出错:SQLSTATE [HY093]:参数号无效:: membernobooking2

该函数传递这些变量:

function makeBooking($memberNo2,$car,$bayID,$bookingDate,$bookingHour,$duration) {}

代码的具体部分是:

$stmt4 = $db->prepare("INSERT INTO booking (bookingid, bayid, bookingdate, bookinghour, duration, memberno, car) 
                VAlUES (DEFAULT, :bayIDBooking, :bookingDateBooking, :bookingHourBooking, :durationBooking, 
                    (SELECT memberNo FROM PeerPark.Member m WHERE (m.email = ':membernobooking') OR (m.nickname = ':membernobooking')), :carBooking) 
                RETURNING bookingid  ");
                    $stmt4->bindValue(':bayIDBooking',$bayID,PDO::PARAM_INT);
                    $stmt4->bindValue(':bookingDateBooking',$bookingDate,PDO::PARAM_STR);
                    $stmt4->bindValue(':bookingHourBooking',$bookingHour,PDO::PARAM_INT);
                    $stmt4->bindValue(':durationBooking',$duration,PDO::PARAM_INT);
                    $stmt4->bindValue(':membernobooking',$memberNo2,PDO::PARAM_STR):
                    $stmt4->bindValue(':carBooking',$car,PDO::PARAM_STR);
                    $stmt4->execute();

我看到有一个非常相似的问题,但我不相信我会得到任何重复。任何人都能解释一下吗?

1 个答案:

答案 0 :(得分:0)

Remove the quotes ' from around your binds in your values.

(m.email = ':membernobooking') OR (m.nickname = ':membernobooking')
           ^                ^                   ^                ^

to

(m.email = :membernobooking) OR (m.nickname = :membernobooking)

Placeholders should not contain quotes.

Reference(s):