mysqli - Close connection in php using database class -
i have created database class in php, , want oop style not procedural style. here code when try close me error. function causing problem.
class mysqldatabase { private $connection; public $message; /** * mysqldatabase constructor. */ public function __construct() { $this->open_connection(); } //object oriented style public function open_connection() { // constant comes form config $this->connection = new mysqli(db_server, db_user, db_pass, db_name); /* * "official" oo way it, */ if ($this->connection->connect_error) { die('connect error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } else { $this->message = "success... " . $this->connection->host_info; } } public function close_connection(){ if (isset($this->connection)) { mysqli_close($this->connection); unset($this->connection); } } }
public function close_connection() { if(isset($this->connection)) { $this->connection->close(); unset($this->connection); } }
Comments
Post a Comment