1

我正在使用 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 de syntaxe près de '' à la ligne 1 在 C:\wamp\www\work\libs\PHP-MySQLi-Database-Class-master\MysqliDb.php第 823 行

查询:连接数据库

>$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'));

我没有看到错误。非常感谢。对不起我的英语不好。

4

3 回答 3

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 . "'" 
于 2014-12-19T12:16:18.163 回答
0

您可以尝试这样调用函数吗:

$db->rawQuery('QUERY', array(), FALSE);

我认为消毒会损害您的查询(它可能会删除 html 字符,在您的情况下是 < > 条件)

假设这是类: https ://github.com/joshcam/PHP-MySQLi-Database-Class/blob/master/MysqliDb.php

于 2014-12-19T12:05:40.377 回答
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']));
于 2020-11-01T14:12:39.217 回答