Ruckusing_Adapter_PgSQL_Base::create_database PHP Method

create_database() public method

Create database cannot run in a transaction block so if we're in a transaction than commit it, do our thing and then re-invoke the transaction
public create_database ( string $db, array $options = [] ) : boolean
$db string the db name
$options array
return boolean
    public function create_database($db, $options = array())
    {
        $was_in_transaction = false;
        if ($this->inTransaction()) {
            $this->commit_transaction();
            $was_in_transaction = true;
        }
        if (!array_key_exists('encoding', $options)) {
            $options['encoding'] = 'utf8';
        }
        $ddl = sprintf("CREATE DATABASE %s", $this->identifier($db));
        if (array_key_exists('owner', $options)) {
            $ddl .= " OWNER = \"{$options['owner']}\"";
        }
        if (array_key_exists('template', $options)) {
            $ddl .= " TEMPLATE = \"{$options['template']}\"";
        }
        if (array_key_exists('encoding', $options)) {
            $ddl .= " ENCODING = '{$options['encoding']}'";
        }
        if (array_key_exists('tablespace', $options)) {
            $ddl .= " TABLESPACE = \"{$options['tablespace']}\"";
        }
        if (array_key_exists('connection_limit', $options)) {
            $connlimit = intval($options['connection_limit']);
            $ddl .= " CONNECTION LIMIT = {$connlimit}";
        }
        $result = $this->query($ddl);
        if ($was_in_transaction) {
            $this->start_transaction();
            $was_in_transaction = false;
        }
        return $result === true;
    }

Usage Example

 /**
  * test dropping database
  */
 public function test_database_droppage()
 {
     $db = "test_db";
     //create it
     $this->assertEquals(true, $this->adapter->create_database($db));
     $this->assertEquals(true, $this->adapter->database_exists($db));
     //drop it
     $this->assertEquals(true, $this->adapter->drop_database($db));
     $this->assertEquals(false, $this->adapter->database_exists($db));
 }
All Usage Examples Of Ruckusing_Adapter_PgSQL_Base::create_database