Postgres::getDatabases PHP Method

getDatabases() public method

Return all database available on the server
public getDatabases ( $currentdatabase = NULL ) : A
$currentdatabase database name that should be on top of the resultset
return A list of databases, sorted alphabetically
    function getDatabases($currentdatabase = NULL)
    {
        global $conf, $misc;
        $server_info = $misc->getServerInfo();
        if (isset($conf['owned_only']) && $conf['owned_only'] && !$this->isSuperUser()) {
            $username = $server_info['username'];
            $this->clean($username);
            $clause = " AND pr.rolname='{$username}'";
        } else {
            $clause = '';
        }
        if ($currentdatabase != NULL) {
            $this->clean($currentdatabase);
            $orderby = "ORDER BY pdb.datname = '{$currentdatabase}' DESC, pdb.datname";
        } else {
            $orderby = "ORDER BY pdb.datname";
        }
        if (!$conf['show_system']) {
            $where = ' AND NOT pdb.datistemplate';
        } else {
            $where = ' AND pdb.datallowconn';
        }
        $sql = "\n\t\t\tSELECT pdb.datname AS datname, pr.rolname AS datowner, pg_encoding_to_char(encoding) AS datencoding,\n\t\t\t\t(SELECT description FROM pg_catalog.pg_shdescription pd WHERE pdb.oid=pd.objoid AND pd.classoid='pg_database'::regclass) AS datcomment,\n\t\t\t\t(SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pdb.dattablespace) AS tablespace,\n\t\t\t\tCASE WHEN pg_catalog.has_database_privilege(current_user, pdb.oid, 'CONNECT') \n\t\t\t\t\tTHEN pg_catalog.pg_database_size(pdb.oid) \n\t\t\t\t\tELSE -1 -- set this magic value, which we will convert to no access later  \n\t\t\t\tEND as dbsize, pdb.datcollate, pdb.datctype\n\t\t\tFROM pg_catalog.pg_database pdb\n\t\t\t\tLEFT JOIN pg_catalog.pg_roles pr ON (pdb.datdba = pr.oid)\n\t\t\tWHERE true\n\t\t\t\t{$where}\n\t\t\t\t{$clause}\n\t\t\t{$orderby}";
        return $this->selectSet($sql);
    }
Postgres