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;
}