/** * MySQL数据库单例实现 * * @author shizqiang at 2015-04-22 * */ final class MySQLFactory { private static $instance; private function __construct() {} public static function getInstance($server, $uname, $passwd, $dbname) { if (!self::$instance) { self::$instance = mysql_connect($server, $uname, $passwd) or die(); mysql_select_db($dbname, self::$instance) or die(); mysql_set_charset(‘utf-8‘, self::$instance); } return self::$instance; } }
$link = MySQLFactory::getInstance(‘localhost‘, ‘root‘, ‘123456‘, ‘test‘);
原文:http://www.cnblogs.com/shizqiang/p/4449000.html