param中的循环变量

时间:2016-09-06 09:17:48

标签: php

我遇到错误“在非对象上调用成员函数bind_param()”

在此行$stmt->bind_param("ss", $influencer_id, $campaign_id);

  public function getCouponDetailsMenu($influencer_id)
  {

    $stmt = $this->con->prepare("SELECT id, campaign_id, campaign_name, status, type_of_campaign, client, brand, influencers, max_coupons, distributed_coupons, expired_coupons, claimed_coupons, coupon_expiry, campaign_start_date, campaign_end_date FROM tbl_campaign WHERE influencers=?");
    $stmt->bind_param("s",$influencer_id);
    $stmt->execute();
    $stmt->bind_result($id, $campaign_id, $campaign_name, $status, $type_of_campaign, $client, $brand, $influencers, $max_coupons, $distributed_coupons, $expired_coupons, $claimed_coupons, $coupon_expiry, $campaign_start_date, $campaign_end_date);
    $campaigns = array();
    while($stmt->fetch()) 
    {

      $temp['id']=$id;
      $temp['campaign_id'] = $campaign_id;
      $temp['campaign_name'] = $campaign_name;
      $temp['status']=$status;
      $temp['type_of_campaign']=$type_of_campaign;
      $temp['client']=$client;
      $temp['brand']=$brand;
      $temp['influencers']=$influencers;
      $temp['max_coupons']=$max_coupons;
      $temp['distributed_coupons']=$distributed_coupons;
      $temp['expired_coupons']=$expired_coupons;
      $temp['claimed_coupons']=$claimed_coupons;
      $temp['coupon_expiry']=$coupon_expiry;
      $temp['campaign_start_date']=$campaign_start_date;
      $temp['campaign_end_date']=$campaign_end_date;
      $temp['logo'] = $this->getDistributedEmail($influencer_id, $campaign_id);
      array_push($campaigns, $temp);
    }
  $stmt->close();
  return $campaigns;

  }

}

//Method to get distributed email
public function getDistributedEmail($influencer_id, $campaign_id)
{
    $stmt = $this->con->prepare("SELECT user_email_address FROM tbl_coupons WHERE influencer_id=? and campaign_id=?");
    $stmt->bind_param("ss", $influencer_id, $campaign_id);
    $stmt->execute();
    $stmt->bind_result($eadd);
    $email = array();
    while($stmt->fetch())
    {
    $temp = $eadd;
    array_push($email, $temp);
    }
    $stmt->close();
    return $email;
}

2 个答案:

答案 0 :(得分:0)

似乎$stmt不是一个对象。尝试在准备电话后立即使用var_dump($stmt);进行调试。

我认为这是因为发送给它的sql语句在当前数据库中无效。

  

听起来就像准备通话失败(不知道为什么),所以它会返回   false - false is not an object,因此您无法致电bind_param()   这一点。

     

如果数据库服务器成功准备语句,PDO :: prepare()将返回PDOStatement对象。如果数据库服务器无法成功准备语句,PDO :: prepare()将返回FALSE或发出PDOException(取决于错误处理)。

答案 1 :(得分:0)

通过添加

来修复它

$ stmt-> store_result();

之后

$温度[' CAMPAIGN_END_DATE'] = $ CAMPAIGN_END_DATE;