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

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); 
 } 
}
上一篇:ORACLE数据库链接


下一篇:Go netpoll I/O 多路复用构建原生网络模型之源码深度解析