<?php class Database{ private static $dbName = 'demo' ; private static $dbHost = 'localhost' ; private static $dbUsername = 'demo'; private static $dbUserPassword = 'demo_password'; private static $con = null; public static function connect() { // One connection through whole application if( null == self::$con ){ try{ self::$con = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword); //self::$con = setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //echo"Database connect succesfully"; } catch(PDOException $e){ die($e->getMessage()); } } return self::$con; } public static function disconnect(){ self::$con = null; } } ?>