单例

  1. class Db {
  2. private static $instance;
  3. public $handle;
  4. Private function __construct($host,$username,$password,$dbname) {
  5. $this->handle=NULL;
  6. $this->getcon($host,$username,$password,$dbname);
  7. }
  8. public static function getBb() {
  9. self::$instance=new Db();
  10. return self::$instance;
  11. }
  12. private function getcon($host,$username,$password,$dbname) {
  13. if($this->handle!=NULL){
  14. return true;
  15. }
  16. $this->handle=mysqli_connect($host,$username,$password,$dbname);
  17. }
  18. }