Created
April 17, 2016 14:26
-
-
Save tingplenting/3459357e1b063d04a9e287f61216d163 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DB { | |
private static $_MYSQL_HOST="localhost"; | |
private static $_MYSQL_USER="your_mysql_user"; | |
private static $_MYSQL_PASS="your_mysql_password"; | |
private static $_MYSQL_DB="your_mysql_database"; | |
private static $connect = null; | |
public function __construct() { | |
die('Init function is not allowed'); | |
} | |
public static function connect() | |
{ | |
if ( null == self::$connect ) | |
{ | |
try | |
{ | |
self::$connect = new PDO( "mysql:host=".self::$_MYSQL_HOST.";"."dbname=".self::$_MYSQL_DB, self::$_MYSQL_USER, self::$_MYSQL_PASS); | |
} | |
catch(PDOException $exception) | |
{ | |
die($exception->getMessage()); | |
} | |
} | |
return self::$connect; | |
} | |
public static function disconnect() | |
{ | |
self::$connect = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment