Guest User

Untitled

a guest
Oct 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. <?php
  2. class DBCxn{
  3. public static $dsn = 'mysql:host=localhost;dbname=webrss';
  4. public static $user = 'root';
  5. public static $pass = 'root';
  6. //保存连接的内部变量
  7. private static $db;
  8. //不能克隆和技巧化
  9. final private function __construct(){}
  10. final private function __clone(){}
  11.  
  12. public static function get(){
  13. if(is_null(self::$db)){
  14. self::$db = new PDO(self::$dsn, self::$user, self::$pass);
  15. }
  16. //返回连接
  17. self::$db->query('set names utf8');
  18. return self::$db;
  19. }
  20. }
  21. ?>
Add Comment
Please, Sign In to add comment