<?php
//定义单例模式
class Single{
//三私一公
private static $instance = null;
private $connect;
private function __clone(){}
private function __construct(){
$connect = mysql_connect('127.0.0.1','root','root');
}
//对外访问的公共静态方法
public static function getInstance($arr){
if(!self::$instance instanceof self){
return self::$instance = new self($arr);
}else{
return self::$instance;
}
}
}
$db1 = Single::getInstance('1');
$db2 = Single::getInstance('2');
var_dump($db2,$db1); |
|