选择语言 :

 Driver_Database_Driver_SQLite::_connect

null Driver_Database_Driver_SQLite::_connect( )
File: ./drivers/database/sqlite/sqlite.class.php
protected function _connect()
{
    $db = $persistent = null;

    extract($this->config['connection']);

    # 检查下是否已经有连接连上去了
    if (Database_Driver_SQLite::$_connection_instance)
    {
        $_connection_id = $this->_get_connection_hash($db);

        if (isset(Database_Driver_SQLite::$_connection_instance[$_connection_id]))
        {
            $this->_connection_ids[$this->_connection_type] = $_connection_id;

            return;
        }
    }

    # 错误服务器
    static $error_host = array();

    $last_error = null;

    for ($i=1; $i<=2; $i++)
    {
        # 尝试重连
        try
        {
            $_connection_id = $this->_get_connection_hash($db);
            Database_Driver_SQLite::$_current_connection_id_to_db[$_connection_id] = Core::debug_path($db);

            $time = microtime(true);
            try
            {
                if ($persistent)
                {
                    $tmplink = sqlite_popen($db);
                }
                else
                {
                    $tmplink = sqlite_open($db);
                }
            }
            catch (Exception $e)
            {
                $error_msg  = $e->getMessage();
                $error_code = $e->getCode();
                $tmplink    = false;
            }

            if (false===$tmplink)
            {
                if (IS_DEBUG)
                {
                    throw $e;
                }
                else
                {
                    $error_msg = 'open sqlite error.';
                }

                throw new Exception($error_msg, $error_code);
            }

            if (IS_DEBUG)Core::debug()->info('sqlite '.Core::debug_path($db).' connection time:' . (microtime(true) - $time));

            # 连接ID
            $this->_connection_ids[$this->_connection_type] = $_connection_id;
            Database_Driver_SQLite::$_connection_instance[$_connection_id] = $tmplink;

            unset($tmplink);

            break;
        }
        catch (Exception $e)
        {
            if (IS_DEBUG)
            {
                Core::debug()->error($db,'open sqlite:'.$db.' error.');
                $last_error = new Exception($e->getMessage(), $e->getCode());
            }
            else
            {
                $last_error = new Exception('open sqlite error.', $e->getCode());
            }

            if ($i==2)
            {
                throw $last_error;
            }

            # 3毫秒后重新连接
            usleep(3000);
        }
    }
}