OOP PHP function Connect, function Disconnect -


slowly getting world of oop php, working on database class , struggling close connection . error receive is;

warning: mysqli_close() expects parameter 1 mysqli, boolean given in c:\users\pc\documents\xampp\htdocs\class.database.php on line 34.

then receive own error message, failed close connection. believe problem variable have in mysqli_close. appreciated. have tried $this->myconn , $myconn no success

<?php  class database{  private $db_host = 'localhost';  private $db_user = 'c3337015';  private $db_pass = 'c3337015';  private $db_name = 'iitb';  public $myconn;  public function connect(){  if(!isset($this->myconn)){  $this->myconn = mysqli_connect($this->db_host,$this->db_user,$this->db_pass,$this->db_name);  if($this->myconn){     $this->myconn = true;     echo "connected";     return true;  }else{ echo "failed"; return false;  }}else{ echo "already connected"; return false;  }   }  public function disconnect() { if(isset($this->myconn)) {     if(mysqli_close($this->myconn)) // error here     {         $this->myconn = false;          echo "connection closed";         return true;      }     else     {     echo "failed close connection";         return false;      }   }else{     echo "no connection prescent"; } }  } 

in specific example don't need wrap mysqli class in anything, since see here you're duplicating constructor, , mysqli::close() functionality, recommend taking @ the mysqli object in php documentation.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -