数据库连接职责的集中控制

 <?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();
?> 
      
      

上一篇文章: zend framework探迷之一 下一篇文章: \d与0-9造成的致命性问题

关于PHP博客

PHP blogger

博客-致力于分享PHP技术的开发心得, 记录站长生活的点点滴滴,PHP博客采用PHP 面向对象编程+Smarty模板引擎+Mysql数据库 开发(全站纯静态化与伪静态化)
QQ:334192009
电邮:admin@PHPdesigner.org

本站搜索

本站最新文章

博客最近档案

友情链接