class Db{
//私有化构造方法
private function __construct()
{
}
//私有化克隆方法
private function __clone()
{
// TODO: Implement __clone() method.
}
protected static $db;
//内部实例化方法
public static function dbInstant($host,$user,$password,$dbname){
if(isset(self::$db)){
return self::$db;
}else{
return self::$db=new PDO("mysql:".$host.";".$dbname,$user,$password);
}
}
}
$db = Db::dbInstant('127.0.0.1','root','root','ceshi');