Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class dbConnection {
- public $CONN;
- private $dbservername, $dbusername, $dbpassword, $dbname;
- public function __construct() {
- $this->dbservername = "localhost";
- $this->dbusername = "dbroot";
- $this->dbpassword = "pass";
- $this->dbname = "test";
- $this->open(); //open the connection on instantization
- }
- public function open() {
- // Create connection
- $this->CONN = new mysqli($this->dbservername, $this->dbusername, $this->dbpassword, $this->dbname);
- // Check connection
- if ($this->CONN->connect_error) {
- die("Connection failed: " . $CONN->connect_error);
- }
- }
- public function prepare($query) {
- //prepare the data
- return $this->CONN->prepare($query);
- }
- public function close() {
- //close the connection
- $this->CONN->close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement