2014-08-29 45 views
1

我想從我的數據庫中獲取一些數據,但mysqli fetch()函數沒有獲取/不工作,它返回false。下面是我正在使用的功能,請幫助。mysqli fetch()不提取

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 2014-08-30 00:10:20

回答

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 
       ); 
    }