2014-08-29 3 views
1

Я пытаюсь получить некоторые данные из моего db, но функция mysqli fetch() не получает/не работает и возвращает false. ниже - это функция, которую я использую, и, пожалуйста, помогите.mysqli fetch() not fetching

public function return_track_order_details($adRef,$transaction_id){ 

    $db = parent::Connect_Database(); 

    $stmt = $db->prepare("SELECT * FROM `s_b_p_h` WHERE `ad_reference` = ? AND `transaction_id` = ? LIMIT 1 "); 

    $stmt->bind_param('ss',$adRef,$transaction_id); 
    $stmt->execute(); 

    $stmt->bind_result(
         $id, 
         $date, 
         $name, 
         $email, 
         $phone, 
         $full_address, 
         $total_amount_paid, 
         $buyers_account_id, 
         $sellers_account_id, 
         $ad_reference, 
         $transaction_id, 
         $status_by_buyers, 
         $status_by_sellers, 
         $net_status 
         ); 
    if($stmt->fetch()){ 

     $id = $this->xss_clean($id); 
     $date = $this->xss_clean($date); 
     $name = $this->xss_clean($name); 
     $email = $this->xss_clean($email); 
     $phone = $this->xss_clean($phone); 
     $full_address = $this->xss_clean($full_address); 
     $total_amount_paid = $this->xss_clean($total_amount_paid); 
     $buyers_account_id = $this->xss_clean($buyers_account_id); 
     $sellers_account_id = $this->xss_clean($sellers_account_id); 
     $ad_reference = $this->xss_clean($ad_reference); 
     $transaction_id = $this->xss_clean($transaction_id); 
     $status_by_buyers = $this->xss_clean($status_by_buyers); 
     $status_by_sellers = $this->xss_clean($status_by_sellers); 
     $net_status = $this->xss_clean($net_status); 

    }else{ 
     return false; 
    } 
} 

любая вещь, я делаю неправильно?

Я использовал также проверить, является ли мое утверждение правильным, а также проверить, выполнено ли оно.

+1

У вас нет ошибок при обращении к базе данных. При этом вверху вашего скрипта и посмотрите, будет ли выбрано исключение: 'mysqli_report (MYSQLI_REPORT_STRICT);' – jeroen

ответ

2

Это довольно смешно, что я пытался сделать здесь. возможно, из-за работы.

Я ничего не возвращал из этой функции, даже если mysqli fecth возвращает true.

поэтому я изменяю инструкцию if ($ stmt-> fetch()) {} для возврата массива.

if($stmt->fetch()){ 

     $id = $this->xss_clean($id); 
     $date = $this->xss_clean($date); 
     $name = $this->xss_clean($name); 
     $email = $this->xss_clean($email); 
     $phone = $this->xss_clean($phone); 
     $full_address = $this->xss_clean($full_address); 
     $total_amount_paid = $this->xss_clean($total_amount_paid); 
     $buyers_account_id = $this->xss_clean($buyers_account_id); 
     $sellers_account_id = $this->xss_clean($sellers_account_id); 
     $ad_reference = $this->xss_clean($ad_reference); 
     $transaction_id = $this->xss_clean($transaction_id); 
     $status_by_buyers = $this->xss_clean($status_by_buyers); 
     $status_by_sellers = $this->xss_clean($status_by_sellers); 
     $net_status = $this->xss_clean($net_status); 

     return array(
       $id, 
       $date, 
       $name, 
       $email, 
       $phone, 
       $full_address, 
       $total_amount_paid, 
       $buyers_account_id, 
       $sellers_account_id, 
       $ad_reference, 
       $transaction_id, 
       $status_by_buyers, 
       $status_by_sellers, 
       $net_status 
       ); 
    }