Skip to content

Instantly share code, notes, and snippets.

@tingplenting
Created April 17, 2016 14:26
Show Gist options
  • Save tingplenting/3459357e1b063d04a9e287f61216d163 to your computer and use it in GitHub Desktop.
Save tingplenting/3459357e1b063d04a9e287f61216d163 to your computer and use it in GitHub Desktop.
<?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