mysqli fetch()没有抓取

时间:2014-08-29 23:55:46

标签: php mysql mysqli

我正在尝试从我的数据库中获取一些数据,但mysqli fetch()函数没有获取/不工作,它返回false。以下是我正在使用的功能,请帮助。

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 个答案:

答案 0 :(得分: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
                );
    }