Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database {
- //MySQL username
- private $username = 'a204737_main';
- //MySQL password
- private $password = 'Kc52GMFf';
- //MySQL hostname
- private $hostname = 'md33.wedos.net:3306';
- //MySQL db
- private $database = 'd204737_main';
- //PDO connection
- private $pdo;
- //log - logging exceptions
- private $log;
- //parameters - parameters for MySQL query
- private $parameters;
- //connection to DB
- private $isDBConnected = FALSE;
- //PDO options
- private $pdoOptions = array (
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //set a error reporting and set a throw exception
- PDO::ATTR_EMULATE_PREPARES => false //disable emulation of prepared statements
- );
- public function __construct($hostname, $database, $username, $password, $pdoOptions) {
- $this->dbConn($hostname, $database, $username, $password, $pdoOptions);
- $this->parameters = array();
- }
- private function dbConn($hostname, $database, $username, $password, $pdoOptions) {
- $dsn = 'mysql:dbname='.$database.';host='.$hostname;
- //connect to db and check exceptions
- try {
- $this->pdo = new PDO($dsn, $username, $password, $pdoOptions);
- $this->isDBConnected = TRUE;
- }
- //if any error occurred
- catch (Exception $e) {
- die ("Connection wasn't established by error: " . $e->getMessage());
- }
- }
- public function closeConn() {
- $this->pdo = null;
- }
- public function getConn() {
- return $this->pdo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement