class Db { 
 private static $instance; 
 public $handle; 
 Private function __construct($host,$username,$password,$dbname) { 
  $this->handle=NULL; 
  $this->getcon($host,$username,$password,$dbname); 
 } 
 public static function getBb() { 
  self::$instance=new Db(); 
  return self::$instance; 
 } 
 private function getcon($host,$username,$password,$dbname) { 
  if($this->handle!=NULL){ 
   return true; 
  } 
  $this->handle=mysqli_connect($host,$username,$password,$dbname); 
 } 
}

PHP面试题:单例模式,创建mysqli数据库链接的单例对象_php