没优化~ 做了个原型
- public $conn;
- public static $sql;
- public static $instance = null;
- public static $instance_test = null;
- private function __construct($host, $user, $password, $database)
- {
- $this->conn = mysql_connect($host, $user, $password, true);
- if (!mysql_select_db($database, $this->conn))
- {
- echo "失败";
- }
- ;
- mysql_query('set names utf8', $this->conn);
- //return $this->conn;
- }
- public static function getInstance()
- {
- if (is_null(self::$instance))
- {
- self::$instance = new db("localhost", "root", "city", "test2");
- }
- return self::$instance;
- }
- public static function getInstance_test()
- {
- if (is_null(self::$instance_test))
- {
- self::$instance_test = new db("localhost", "root", "city", "test");
- }
- return self::$instance_test;
- }