Guest User

Untitled

a guest
Oct 14th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. class utility
  2. {
  3. //initialize the connection variables.
  4. private $username = "";
  5. private $password = "";
  6. private $host = "";
  7. private $database = "";
  8.  
  9. public $mysqli = "";
  10. public $error;
  11.  
  12. //Opens the database connection.
  13. function db_open()
  14. {
  15. $this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->database);
  16.  
  17. if($this->mysqli->connect_errno != 0) {
  18. $this->error = "Could not connect: " . $this->mysqli->connect_error;
  19. return false;
  20. } else {
  21. return $this->mysqli;
  22. }
  23. }
  24.  
  25. //Kills the active database connection.
  26. function db_close()
  27. {
  28. $thread = $this->mysqli->thread_id; //Get active thread.
  29. $this->mysqli->kill($thread); //Kill the thread.
  30. $this->mysqli->close(); //Close the link
  31.  
  32. return "Connection closed";
  33. }
  34. }
Add Comment
Please, Sign In to add comment