db_Mysql::connect PHP Method

connect() public method

连接数据库方法
public connect ( $config = '', $linkNum, $force = false )
    public function connect($config = '', $linkNum = 0, $force = false)
    {
        if (!isset($this->linkID[$linkNum])) {
            if (empty($config)) {
                $config = $this->config;
            }
            // 处理不带端口号的socket连接情况
            $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
            // 是否长连接
            $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
            if ($pconnect) {
                $this->linkID[$linkNum] = mysql_pconnect($host, $config['username'], $config['password'], 131072);
            } else {
                $this->linkID[$linkNum] = mysql_connect($host, $config['username'], $config['password'], true, 131072);
            }
            if (!$this->linkID[$linkNum] || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum])) {
                //E(mysql_error());
                throw new Exception(mysql_error());
            }
            $dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
            //使用UTF8存取数据库
            mysql_query("SET NAMES '" . $config['charset'] . "'", $this->linkID[$linkNum]);
            //设置 sql_model
            if ($dbVersion > '5.0.1') {
                mysql_query("SET sql_mode=''", $this->linkID[$linkNum]);
            }
        }
        return $this->linkID[$linkNum];
    }