call to a member function execute() on a non-object

前端 未结 4 2110
北荒
北荒 2020-12-11 20:28

My script containing that error is this:

$stmt = $this->db->prepare(\'SELECT libelle,activite,adresse,tel,lat,lng FROM etablissements where type IN (\'         


        
相关标签:
4条回答
  • 2020-12-11 21:01

    $stmt is supposed to be an object with the method execute().
    Seems like $this->db->prepare() is not returning the good result.

    If $this->db is a mysqli() object you should bind the parameters like that:

    if ($stmt = $this->db->prepare('SELECT libelle,activite,adresse,tel,lat,lng FROM etablissements where type IN (?)')) {
      $stmt->bind_param("s", $in_list);
      $stmt->execute();
      // ...
    }
    
    0 讨论(0)
  • 2020-12-11 21:05

    Swap the statement bind and execute and replace result with param, It will work fine

    $stmt = $this->db->prepare('SELECT libelle,activite,adresse,tel,lat,lng FROM etablissements 
    where type IN ('.$in_list.')');
    $stmt->bind_param($libelle,$activite,$adresse,$tel,$lat,$lng);
    $stmt->execute();
    
    0 讨论(0)
  • 2020-12-11 21:11

    Check the sql you executed,

    $this->db->prepare('SELECT libelle,activite,adresse,tel,lat,lng FROM etablissements where type IN ('.$in_list.')');
    

    does not return a valid statement object.

    0 讨论(0)
  • 2020-12-11 21:16

    Your db object is null. Check if you close the connection too early or somehow you override it to null.

    0 讨论(0)
提交回复
热议问题