Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database {
- // Database Connection Properties
- protected $host;
- protected $dbname;
- protected $username;
- protected $password;
- protected $connection;
- protected $connectionStatus;
- public function __construct($host, $dbname, $username, $password)
- {
- $this->host = $host;
- $this->dbname = $dbname;
- $this->username = $username;
- $this->password = $password;
- }
- // Setup a Connection to the Database
- protected function setupConnection()
- {
- try
- {
- $connection = new PDO("mysql:host=$this->host;dbname=$this->dbname;charset=UTF8", $this->username, $this->password);
- $this->connection = $connection;
- }
- catch (PDOException $e)
- {
- echo "Cannot Connect to Database (" . $e->getMessage() . ")";
- }
- }
- // Connect to the Database
- public function dbConnect()
- {
- $this->setupConnection();
- }
- // Get and output the status of the database connection
- public function getStatus()
- {
- // Check the database connection status
- if($this->connection)
- {
- $this->connectionStatus = true;
- var_dump($this->connectionStatus);
- }
- else
- {
- $this->connectionStatus = false;
- var_dump($this->connectionStatus);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement