Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class utility
- {
- //initialize the connection variables.
- private $username = "";
- private $password = "";
- private $host = "";
- private $database = "";
- public $mysqli = "";
- public $error;
- //Opens the database connection.
- function db_open()
- {
- $this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->database);
- if($this->mysqli->connect_errno != 0) {
- $this->error = "Could not connect: " . $this->mysqli->connect_error;
- return false;
- } else {
- return $this->mysqli;
- }
- }
- //Kills the active database connection.
- function db_close()
- {
- $thread = $this->mysqli->thread_id; //Get active thread.
- $this->mysqli->kill($thread); //Kill the thread.
- $this->mysqli->close(); //Close the link
- return "Connection closed";
- }
- }
Add Comment
Please, Sign In to add comment