title: Call to a member function prepare() on a non-object in (non object)
body: <p>I get this error: Call to a member function prepare() on a non-object in line 25.
  I have marked the line 25 that it's referring to; can someone please check and tell what's wrong? I tried all possible ways, but can't figure it out.</p>
  
  <p>class db</p>
  
  <pre><code>class db {
  
  public $connect;
  private $username = "root";
  private $password = "";
  private $dns="mysql:host=localhost;dbname=etrharam_db";
  private $method=array(PDO::MYSQL_ATTR_INIT_COMMAND=&gt;"set name utf8");
  
  public function connection(){
      $connect= new PDO($this-&gt;dns,$this-&gt;username,$this-&gt;password,$this-&gt;method);
      return $connect;
  }/*connection*/
  
  public function Idu($query,$data){
      $pre=$this-&gt;connect-&gt;prepare($query);
      foreach($data as $index=&gt;$val){
          $pre-&gt;bindValue($index+1,$val);
      }
      $pre-&gt;execute();
  }/*idu*/    
  
  public function Select($query,$data){
      $pre=$this-&gt;connect-&gt;prepare($query);
      foreach($data as $index=&gt;$val){
          $pre-&gt;bindValue($index+1,$val);
      }
      $pre-&gt;execute();
      $res=$pre-&gt;fetchAll(PDO::FETCH_ASSOC);
      return $res;
  }/*select*/
  
  }/*db*/
  </code></pre>
  
  <p>test.php</p>
  
  <pre><code>include ('oop.php');
  $oop= new db;
  $query="SELECT * FROM `newcoll_tbl` WHERE id=?";
  $data=array('1');
  $res=$oop-&gt;Select($query,$data);
  print_r($res);
  </code></pre>
  
  <p>what is the problem?
  Thank you in advance.</p>