数据库连接职责的集中控制
<?php
/**
* 数据库连接职责的集中控制
* @author:PHP博客-技术-资源-技术站-面向对象
*/
class Mysql{
/*数据库连接返回*/
private $connect;
private static $instance;
private function __construct(){
$this->connect = mysql_connect('localhost','root','123456')
or die('数据库连接失败');
mysql_select_db("blog");
}
private function __clone(){
}
public function getInstance(){
if (!(self::$instance instanceof self)) {
self::$instance = new self();
}
return self::$instance;
}
public function otherMethod(){
printf("otherMethod");
}
}
$db = Mysql::getInstance();
$db->otherMethod();
?>