mysqli fetch() not fetching

2019-04-16 02:50发布

问题:

I am trying to fetch some data from my db, but mysqli fetch() function is not fetching / not working and it is returning false. below is the function i am using and please help.

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

any thing i am doing wrong?

i have used also check if my statement is right and also check if it executed.

回答1:

It's quite funny what i was trying to do here. maybe because of over work.

I was not returning anything from this function even if mysqli fecth returns true.

so i modify the if($stmt->fetch()){} statement to return an array.

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


标签: php mysql mysqli