Retrieve a database object from a connection

@param string $database database name
@param boolean $wrap whether to wrap in a Database object

@return Database|MongoDB
5332
public function database($database, $wrap = true)
    {
        $database = $this->connection->{$database};

        return $wrap ? new Database($database, $this) : $database;
    }
651897
public function getDatabase()
    {
        if ($this->_oDatabaseObject === null) {
            $this->_oDatabaseObject = oxDb::getDb(oxDb::FETCH_MODE_ASSOC);
        }

        return $this->_oDatabaseObject;
    }
303969
public static function drop_db($database = null)
	{
		if (empty($database))
		{
			throw new \Mongo_DbException('Failed to drop MongoDB database because name is empty');
		}

		else
		{
			try
			{
				static::instance()->connection->{$database}->drop();
				return true;
			}
			catch (\Exception $e)
			{
				throw new \Mongo_DbException("Unable to drop Mongo database `{$database}`: {$e->getMessage()}", $e->getCode());
			}

		}
	}
727805
public static function get($id = null)
    {
        if ($id === null && static::$activeDatabaseConnection === null) {
            throw new MissingDatabaseConnectionException('No databases defined.');
        }

        if ($id === null) {
            return static::$databaseConnections[static::$activeDatabaseConnection];
        } else {
            return static::$databaseConnections[$id];
        }
    }
213722
public function setDatabase($database)
    {
        $database = empty($database)
            ? $this->database
            : $database;

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

        return $this;
    }
823242
public function connectDatabase($database = array())
    {
        $model = new BaseModel();
        if (isset($this->options['debugStatus']) && $this->options['debugStatus'] === TRUE) {
            $model->debugStatus = $this->options['debugStatus'];
            if (isset($this->options['debugLevel']) && !empty($this->options['debugLevel'])) {
                $model->debugLevel = $this->options['debugLevel'];
            }
            if (isset($this->options['loggerPath']) && !empty($this->options['loggerPath'])) {
                $model->debugLoggerPath = $this->options['loggerPath'];
            }
            $model->debugLoggerFilename = 'Log-' . date('Y-m-d') . '.log';
            $model->__construct();
        }
        $model->setDatabase($database);

        return $model;
    }
33403
public function getTables($database=null)
    {
        if (is_null($this->tables)) {
            $sql    = !empty($database) ? 'SHOW TABLES FROM '.$database : 'SHOW TABLES';
            $this->query($sql);
            $result = $this->fetchAll();
            foreach ($result as $v) {
                $this->tables[] = array_values($v)[0];
            }
        }
        return $this->tables;
    }
642551
private function getDb($transaction, $object)
    {
        if($object instanceof \Imi\Model\Model)
        {
            $db = Db::getInstance(ModelManager::getDbPoolName($object));
        }
        else
        {
            $db = Db::getInstance($transaction->dbPoolName);
        }
        return $db;
    }
134085
public function useDb($database)
    {
        switch ($this->driver) {
            case 'mysql':
                $this->query("USE `$database`");
                $this->dbname = $database;
                break;

            default:
                throw new \RuntimeException(sprintf('Unsupported switching database for current driver: %s', $this->driver));
        }
        return $this;
    }
854297
function getDatabaseConnector(database, options, callback) {
    if (typeof options === "function") {
        callback = options
        options = {}
    }

    options = extend({}, defaults, options)

    var server = new Server(options.host, options.port, options.serverOptions)
        , databaseConnector = new Db(database, server, options.dbOptions)

    databaseConnector.open(authOrReturn)

    function authOrReturn(err, db) {
        if (err) {
            return callback(err)
        }

        if (options.user || options.password) {
            db.authenticate(options.user, options.password
                , options.authenticateOptions, returnDb)
        } else {
            callback(null, db)
        }

        function returnDb(err, success) {
            if (err) {
                return callback(err)
            }

            if (!success) {
                return callback(new Error("auth failed"))
            }

            callback(null, db)
        }
    }
}
1105630
protected function db()
    {
        if (!isset($this->database)) {
            throw new RuntimeException(sprintf(
                'Database Connection is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->database;
    }
1118041
public function get_statement( $db ) {
		$statement = $db->prepare( $this->get_sql() );
		foreach ( $this->values_to_bind as $name => $value ) {
			if ( false === $value['data_type'] ) {
				$statement->bindValue( $name, $value['value'] );
			} else {
				$statement->bindValue( $name, $value['value'], $value['data_type'] );
			}
		}
		return $statement;
	}
710006
public static function load($db = null)
    {
        if (!isset(self::$_instance)) {
            self::$_instance = new Validator($db);
        }

        return self::$_instance;
    }
944547
public function db_select($database = '')
	{
		if ($database === '')
		{
			$database = $this->database;
		}

		if (mysql_select_db($database, $this->conn_id))
		{
			$this->database = $database;
			return TRUE;
		}

		return FALSE;
	}
443975
public function fetch_object($sql)
    {

        if (empty($sql)) return false;

        $res    = $this->query($sql);
        $result = @mysql_fetch_object($res);
        $this->free($res);

        return $result;
    }
1185
public static function getInstance($database = null)
    {

        if (self::$instance instanceof Pool) {
            self::$instance->add($database);

            return self::$instance;
        }

        self::$instance = new Pool($database);

        return self::$instance;
    }
623891
private function _checkdatabase($database)
    {

        if (count($this->_collection) == 0) {
            $this->_collection[$database] = new $database();

            return $this->_collection[$database];
        }

        $new = false;
        foreach ($this->_collection as $db) {
            if ($db === $database) continue;
            $new = true;
        }

        if ($new === true) {
            $this->_collection[$database] = new $database();
        }

        return false;
    }