我正在使用PHP-MySQLi-Database-Class(MysqliDb.php)。
我有这个问题,但是Wamp说:
致命错误:准备查询时出现问题
SELECT car_id FROM gm_cars WHERE car_id NOT IN
(
SELECT reserve_car_id FROM gm_reservations
WHERE reserve_dropOff > ? AND reserve_dropOff = ? AND reserve_pickUp )
Erreur desyntaxeprèsde''àlaligne 1 in
第823行C:\wamp\www\work\libs\PHP-MySQLi-Database-Class-master\MysqliDb.php
查询: 连接数据库
>$carsBetweenDates = $db->rawQuery
('SELECT car_id FROM gm_cars WHERE car_id NOT IN
(SELECT reserve_car_id FROM gm_reservations
WHERE reserve_dropOff > ? AND reserve_dropOff <= ?
UNION
DISTINCT SELECT reserve_car_id FROM gm_reservations
WHERE reserve_pickUp >= ? AND reserve_pickUp < ?)',
Array('2014-12-20 20:00:00', '2014-12-22 20:00:00',
'2014-12-20 20:00:00', '2014-12-22 20:00:00'));
我没有看到错误。非常感谢。抱歉我的英文。
答案 0 :(得分:0)
你可以尝试这样调用这个函数:
$db->rawQuery('QUERY', array(), FALSE);
我认为清理会损害您的查询(它可能会删除HTML字符,在您的情况下会&lt;&gt;条件)
假设这是班级: https://github.com/joshcam/PHP-MySQLi-Database-Class/blob/master/MysqliDb.php
答案 1 :(得分:0)
尝试更改查询以简化查询。首先,将两个表合并为一个,然后反转条件以部分删除“NOT IN”
SELECT gm_cars.car_id
FROM gm_cars LEFT JOIN gm_reservations
ON gm_cars.car_id = gm_reservations.reserve_car_id
WHERE (reserve_dropOff <= ? OR reserve_dropOff > ?)
AND (reserve_pickUp < ? OR reserve_pickUp >= ?)
AND gm_cars.car_id NOT IN Array('...')
GROUP BY gm_cars.car_id
还有一件事,我假设你要替换“?”使用最终查询中的值,如果您想要更通用的查询,可以执行以下操作:( PHP中的示例)
$queryStaff = "SELECT STAFF.id FROM STAFF WHERE name = '" . $your_variable . "'"
答案 2 :(得分:0)
一个例子。
$db->rawQuery("SELECT * FROM print_orders WHERE print_guests.id = print_orders.id AND print_order_products.order_id = print_orders.id AND print_orders.id = ? AND print_guests.email = ? AND print_order_products.order_id = ? " , array($_POST['orden'], $_POST['email'], $_POST['orden']));