2016-04-05 21 views
0

setAttribute(PDO::ATTR_EMULATE_PREPARES, false);'u ayarladıktan sonra MySQL select sorgusu artık çalışmayacaktı, kimse nedenini biliyor mu?PDO :: ATTR_EMULATE_PREPARES issue

if($_POST) 
{ 
    $user_checkin  = test_input($_POST['checkin']); 
    $user_checkout = test_input($_POST['checkout']); 
    $user_noofpeople = test_input($_POST['noofpeople']); 
    $user_roomtype = test_input($_POST['roomtype']); 

    try 
    { 

     $stmt = $db_con->prepare(" 
      SELECT r.* 
       FROM system_apartment AS r 
      WHERE r.apartment_type = :user_roomtype 
       AND r.apartment_capacity >= :user_capacity 
       AND r.apartment_id 
      NOT IN 
       (
        SELECT b.booking_apartmentid 
         FROM system_booking AS b 
        WHERE (b.booking_date_checkout >= :user_checkin AND b.booking_date_checkin <= :user_checkout) 
         OR (b.booking_date_checkin <= :user_checkin AND b.booking_date_checkout >= :user_checkout) 
       ); 
     "); 
     $stmt->bindParam(':user_checkin', $user_checkin, PDO::PARAM_STR); 
     $stmt->bindParam(':user_checkout', $user_checkout, PDO::PARAM_STR); 
     $stmt->bindParam(':user_roomtype', $user_roomtype, PDO::PARAM_STR); 
     $stmt->bindParam(':user_capacity', $user_noofpeople, PDO::PARAM_INT); 
     $stmt->execute(); 
     $count = $stmt->fetchAll(); 
     $count = count($count); 

     if($count==0){ 
      echo "noapartments"; // not available 
     } 
     else{ 
      echo "searchcomplete"; // not available 
     } 

    } 
    catch(PDOException $e){ 
     echo $e->getMessage(); 
    } 
} 

Özniteliği false olarak ayarlamadan önce kod gayet iyi çalışıyordu.

cevap

0

PREPARE öykünmesini devre dışı bırakırsanız, aynı yer tutucuyu birden çok kez kullanamazsınız. :user_checkin ve :user_checkout farklı yer tutucuların her birini kullanmanız gerekir.

$stmt = $db_con->prepare(" 
     SELECT r.* 
      FROM system_apartment AS r 
     WHERE r.apartment_type = :user_roomtype 
      AND r.apartment_capacity >= :user_capacity 
      AND r.apartment_id 
     NOT IN 
      (
       SELECT b.booking_apartmentid 
        FROM system_booking AS b 
       WHERE (b.booking_date_checkout >= :user_checkin AND b.booking_date_checkin <= :user_checkout) 
        OR (b.booking_date_checkin <= :user_checkin2 AND b.booking_date_checkout >= :user_checkout2) 
      ); 
    "); 
    $stmt->bindParam(':user_checkin', $user_checkin, PDO::PARAM_STR); 
    $stmt->bindParam(':user_checkout', $user_checkout, PDO::PARAM_STR); 
    $stmt->bindParam(':user_checkin2', $user_checkin, PDO::PARAM_STR); 
    $stmt->bindParam(':user_checkout2', $user_checkout, PDO::PARAM_STR); 
    $stmt->bindParam(':user_roomtype', $user_roomtype, PDO::PARAM_STR); 
    $stmt->bindParam(':user_capacity', $user_noofpeople, PDO::PARAM_INT);