创建一个数据库
boolean Driver_Database_Driver_MySQL::create_database( string $database [, string $charset = null , string $collate = null ] )
参数列表
参数 类型 描述 默认值 $database
string
$database $charset
string
编码,不传则使用数据库连接配置相同到编码 null $collate
string
整理格式 null
boolean
public function create_database($database, $charset = null, $collate=null)
{
$config = $this->config;
$this->config['connection']['database'] = null;
if (!$charset)
{
$charset = $this->config['charset'];
}
$sql = 'CREATE DATABASE ' . $this->_quote_identifier($database) . ' DEFAULT CHARACTER SET ' . $charset;
if ($collate)
{
$sql .= ' COLLATE '.$collate;
}
try
{
$result = $this->query($sql, null, true)->result();
$this->config = $config;
return $result;
}
catch (Exception $e)
{
$this->config = $config;
throw $e;
}
}