Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database {
- private static $db = "homemadecrafts";
- private static $host = "localhost";
- private static $username = "";
- private static $password = "";
- private static $conn = null;
- public function __construct(){
- die("Initialization is not allowed");
- }
- public static function connect(){
- if(null == self::$conn){
- try {
- self::$conn = new PDO("mysql:host=".self::$host.";"."dbname=".self::$db, self::$username, self::$password);
- self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch(PDOException $e){
- echo "Connection failed " . $e->getMessage();
- }
- }
- return self::$conn;
- }
- public static function disconnect(){
- self::$conn = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement