Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DBConnection {
- protected $username = '';
- protected $password = '';
- protected $dbName = '';
- protected $hostName = '';
- function __construct($username, $password, $dbName, $hostname) {
- $this->username = $username;
- $this->password = $password;
- $this->dbName = $dbName;
- $this->hostName = $hostname;
- }
- public function getUsername() {
- return $this->username;
- }
- public function getPassword() {
- return $this->password;
- }
- public function getDbName() {
- return $this->dbName;
- }
- public function getHostName() {
- return $this->hostName;
- }
- /**
- * Create a PDO connection.
- * @return PDO
- */
- public function connect() {
- try {
- $dbh = new PDO('mysql:host=' . $this->hostName . ';dbname=' . $this->dbName, $this->username, $this->password);
- return $dbh;
- }
- catch (PDOException $e) {
- error_log('Error Could not connect to database. PDOException: ' . $e->getMessage());
- return false;
- }
- }
- }
- $dbh = (new DBConnection('appname', 'lhlftlvevlergjidjbgvtdkdlhrfd', 'appname', 'localhost'))->connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement