Starts the connection instance, if it has already been declared before, does not duplicate it and saves memory.

@param array $database

@return connection instance
547929
public static function start(array $database = [], bool $new_instance = false)
    {
        if (!self::$instance instanceof self or $new_instance) {
            self::$instance = new self($database);
        }

        return self::$instance;
    }
1070236
protected function reconnect($key, $database)
    {
        $connections = DB::getConnections();
        /** @var MySqlConnection $connection */
        $connection = isset($connections[$key]) ? $connections[$key] : '';

        if (is_object($connection) && $connection->getDatabaseName() != $database) {
            $connection->setDatabaseName($database);
            $connection->reconnect();
        }
    }
213722
public function setDatabase($database)
    {
        $database = empty($database)
            ? $this->database
            : $database;

        if (is_file($database)) {
            $this->handle->open($database);
            $this->database = $database;
        }

        return $this;
    }
556389
protected function _select_db($database)
	{
		if ( ! mysql_select_db($database, $this->_connection))
		{
			// Unable to select database
			throw new \Database_Exception(mysql_error($this->_connection), mysql_errno($this->_connection));
		}

		static::$_current_databases[$this->_connection_id] = $database;
	}
1026152
public static function getInstance($db = null) {

        if (empty(self::$instance)) {

            if (is_null($db)) {
                throw new \RuntimeException('Empty params');
            }

            self::$instance = new Acl($db);
        }

        return self::$instance;
    }
1089926
public static function hard_reset( $database = null )
	{
		$tables = DB::fetch( 'SHOW TABLES', array(), $database, array( 'assoc' ) );
		
		foreach( $tables as $table )
		{
			DB::run( 'DROP TABLE IF EXISTS '.reset( $table ), array(), $database );
		}
	}
239521
private function _connected (array $db)
    {
        try {
            $connection = mysqli_connect ($db['host'], $db['username'], $db['password'], $db['name']);

            return $connection ? true : false;
        } catch (\Exception $e) {
            return false;
        }
    }
352610
public function connection()
    {
        if (!is_object($this->db)) {
            $this->db = new \MysqliDb();
            $this->db->addConnection($this->dbName, $this->database);
        }

        return $this;
    }
601660
public function getBackupInstance($database = null)
	{
		$configuration = array_merge($this->getConfig('database'), $this->getConfig('backup::config'));
		$this->backupInstance = $this->backupFactory->build($configuration, $database);

		return $this->backupInstance;
	}
683546
public function getDatabase(string $database): DatabasePartial
    {
        if (!$this->hasDatabase($database)) {
            throw new ConfigException("Undefined database `{$database}`.");
        }

        $config = $this->config['databases'][$database];

        return new DatabasePartial(
            $database,
            $config['tablePrefix'] ?? $config['prefix'] ?? '',
            $config['connection'] ?? $config['write'] ?? $config['driver'],
            $config['readConnection'] ?? $config['read'] ?? $config['readDriver'] ?? null
        );
    }
122975
static public function getInstance($db, $singleton = true)
    {
        static $cache = array();

        if (!isset($cache[$db]) || !$singleton) {
            $obj    = new self();
            $config = config('ssdb.' . $db);
            if (!$config) {
                throw new \RuntimeException('ssdb config error.');
            }
            $obj->host = $config['host'];
            $obj->port = $config['port'];
            $obj->connect($obj->host, $obj->port);
            $cache[$db] = $obj;
        }

        return $cache[$db];
    }
1197141
public function initDb(array $connections): void{
        $this->db = new Database();
        foreach ($connections as $name => $settings) {
            $this->db->addConnection($settings, $name);
        }
    }
717481
public static function connect($host = null, $database = null, $user = null, $password = null)
    {
        if (config('app.setup')) {
            self::$connection = new MysqlConnector($host, $database, $user, $password);
            self::$server = self::$connection->connector;
        }

        return self::$server;
    }
670967
public function database(string $database = null): DatabaseInterface
    {
        if (empty($database)) {
            $database = $this->config->getDefaultDatabase();
        }

        //Spiral support ability to link multiple virtual databases together using aliases
        $database = $this->config->resolveAlias($database);

        if (isset($this->databases[$database])) {
            return $this->databases[$database];
        }

        if (!$this->config->hasDatabase($database)) {
            throw new DBALException(
                "Unable to create Database, no presets for '{$database}' found"
            );
        }

        return $this->databases[$database] = $this->makeDatabase(
            $this->config->getDatabase($database)
        );
    }
881618
public function on($connection)
    {
        if (array_key_exists($connection, $this->connections)) {
            $this->defaultConnection = $connection;
        }
        return $this;
    }
734652
protected function getNewMySqlConnection(array $config, string $connection = null)
    {
        if ($connection && isset($config[$connection])) {
            $config = array_merge($config, $config[$connection]);
        }

        return ConnectorFactory::make(FW::version())->connect($config);
    }
713065
public static function open($database)
    {
        // abre uma conexão e armazena na propriedade estática $conn
        if (empty(self::$conn))
        {
            self::$conn = TConnection::open($database);
            // inicia a transação
            self::$conn->beginTransaction();
            // desliga o log de SQL
            self::$logger = NULL;
        }
    }