Пример #1
0
 public function connect($test = false)
 {
     if (is_resource($this->link)) {
         return $this->link;
     }
     $connect = $this->config['pconnect'] == TRUE ? 'mysql_pconnect' : 'mysql_connect';
     $host = $this->config['hostname'];
     $host = empty($this->config['hostport']) ? $host : $host . ':' . $this->config['hostport'];
     $user = $this->config['username'];
     $pass = $this->config['password'];
     $database = $this->config['database'];
     if ($this->link = @$connect($host, $user, $pass, true)) {
         if (@mysql_select_db($database, $this->link)) {
             $version = $this->version();
             if ($version >= '4.1' && ($charset = $this->config['charset'])) {
                 mysql_query("SET NAMES '" . $charset . "'", $this->link);
                 //使用UTF8存取数据库 需要mysql 4.1.0以上支持
             }
             if ($version > '5.0.1') {
                 mysql_query("SET sql_mode=''", $this->link);
                 //设置 sql_model
             }
         } else {
             if ($test) {
                 return -2;
             }
             zotop::error(-2, 'Could not connect to database');
         }
     } else {
         if ($test) {
             return -1;
         }
         zotop::halt(-1, 'Could not connect to database server (' . $this->config['hostname'] . ')');
     }
     return false;
 }