Postgres::createRole PHP Method

createRole() public method

Creates a new role
public createRole ( $rolename, $password, $superuser, $createdb, $createrole, $inherits, $login, $connlimit, $expiry, $memberof, $members, $adminmembers )
$rolename The name of the role to create
$password A password for the role
$superuser Boolean whether or not the role is a superuser
$createdb Boolean whether or not the role can create databases
$createrole Boolean whether or not the role can create other roles
$inherits Boolean whether or not the role inherits the privileges from parent roles
$login Boolean whether or not the role will be allowed to login
$connlimit Number of concurrent connections the role can make
$expiry String Format 'YYYY-MM-DD HH:MM:SS'. '' means never expire
$memberof (array) Roles to which the new role will be immediately added as a new member
$members (array) Roles which are automatically added as members of the new role
$adminmembers (array) Roles which are automatically added as admin members of the new role
    function createRole($rolename, $password, $superuser, $createdb, $createrole, $inherits, $login, $connlimit, $expiry, $memberof, $members, $adminmembers)
    {
        $enc = $this->_encryptPassword($rolename, $password);
        $this->fieldClean($rolename);
        $this->clean($enc);
        $this->clean($connlimit);
        $this->clean($expiry);
        $this->fieldArrayClean($memberof);
        $this->fieldArrayClean($members);
        $this->fieldArrayClean($adminmembers);
        $sql = "CREATE ROLE \"{$rolename}\"";
        if ($password != '') {
            $sql .= " WITH ENCRYPTED PASSWORD '{$enc}'";
        }
        $sql .= $superuser ? ' SUPERUSER' : ' NOSUPERUSER';
        $sql .= $createdb ? ' CREATEDB' : ' NOCREATEDB';
        $sql .= $createrole ? ' CREATEROLE' : ' NOCREATEROLE';
        $sql .= $inherits ? ' INHERIT' : ' NOINHERIT';
        $sql .= $login ? ' LOGIN' : ' NOLOGIN';
        if ($connlimit != '') {
            $sql .= " CONNECTION LIMIT {$connlimit}";
        } else {
            $sql .= ' CONNECTION LIMIT -1';
        }
        if ($expiry != '') {
            $sql .= " VALID UNTIL '{$expiry}'";
        } else {
            $sql .= " VALID UNTIL 'infinity'";
        }
        if (is_array($memberof) && sizeof($memberof) > 0) {
            $sql .= ' IN ROLE "' . join('", "', $memberof) . '"';
        }
        if (is_array($members) && sizeof($members) > 0) {
            $sql .= ' ROLE "' . join('", "', $members) . '"';
        }
        if (is_array($adminmembers) && sizeof($adminmembers) > 0) {
            $sql .= ' ADMIN "' . join('", "', $adminmembers) . '"';
        }
        return $this->execute($sql);
    }
Postgres