Created
May 27, 2012 03:59
-
-
Save andy12530/2802115 to your computer and use it in GitHub Desktop.
Connect the DB
This file contains 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 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