Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment