コード例 #1
0
 /**
  * 取得实例
  * 
  * @access public
  * @param mixed $dbinfo
  * @return mixed
  */
 public static function getInstance($dbinfo)
 {
     self::$dbinfo = $dbinfo;
     if (!self::$dbo instanceof self) {
         self::$conn = mysql_connect($dbinfo['host'], $dbinfo['user'], $dbinfo['password']);
         if (self::$conn === false) {
             trigger_error('<span style="color:red;border:red 1px solid;padding:0.5em;">无法连接数据库,请检查数据库连接参数!</span>', E_USER_ERROR);
             exit;
         }
         $charset = isset($dbinfo['charset']) ? $dbinfo['charset'] : 'utf8';
         mysql_query("set names '{$charset}'");
         mysql_select_db($dbinfo['name'], self::$conn);
         self::$dbo = new self();
     }
     return self::$dbo;
 }