Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Database {
- // Database Connection Properties
- protected $host;
- protected $dbname;
- protected $username;
- protected $password;
- protected $dbStatus;
- public function __construct($host, $dbname, $username, $password)
- {
- $this->host = $host;
- $this->dbname = $dbname;
- $this->username = $username;
- $this->password = $password;
- }
- // Setup a Database Connection
- protected function dbConnection()
- {
- try
- {
- $conn = new PDO("mysql:host=$this->host;dbname=$this->dbname;charset=UTF8", $this->username, $this->password);
- $this->dbStatus = "connected";
- }
- catch (PDOException $e)
- {
- echo "Cannot Connect to Database (" . $e->getMessage() . ")";
- $this->dbStatus = "</br>" . "not connected";
- }
- }
- // Connect to the Database
- public function dbConnect()
- {
- $this->dbConnection();
- echo "<h2>" . $this->dbStatus . "</h2>";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement