Advertisement
Guest User

Untitled

a guest
Aug 14th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. Class dbConnection {
  2.  
  3. public $CONN;
  4. private $dbservername, $dbusername, $dbpassword, $dbname;
  5.  
  6. public function __construct() {
  7.  
  8. $this->dbservername = "localhost";
  9. $this->dbusername = "dbroot";
  10. $this->dbpassword = "pass";
  11. $this->dbname = "test";
  12. $this->open(); //open the connection on instantization
  13. }
  14.  
  15. public function open() {
  16.  
  17. // Create connection
  18. $this->CONN = new mysqli($this->dbservername, $this->dbusername, $this->dbpassword, $this->dbname);
  19.  
  20. // Check connection
  21. if ($this->CONN->connect_error) {
  22. die("Connection failed: " . $CONN->connect_error);
  23.  
  24. }
  25.  
  26. }
  27.  
  28. public function prepare($query) {
  29. //prepare the data
  30. return $this->CONN->prepare($query);
  31.  
  32. }
  33.  
  34. public function close() {
  35. //close the connection
  36. $this->CONN->close();
  37.  
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement