Skip to content

Instantly share code, notes, and snippets.

@andy12530
Created May 27, 2012 03:59
Show Gist options
  • Save andy12530/2802115 to your computer and use it in GitHub Desktop.
Save andy12530/2802115 to your computer and use it in GitHub Desktop.
Connect the DB
<?php
class DBCxn{
public static $dsn = 'mysql:host=localhost;dbname=webrss';
public static $user = 'root';
public static $pass = 'root';
//保存连接的内部变量
private static $db;
//不能克隆和技巧化
final private function __construct(){}
final private function __clone(){}
public static function get(){
if(is_null(self::$db)){
self::$db = new PDO(self::$dsn, self::$user, self::$pass);
}
//返回连接
self::$db->query('set names utf8');
return self::$db;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment