for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Class CreateDatabase
*
* @filesource CreateDatabase.php
* @created 12.06.2017
* @package chillerlan\Database\Query\Dialects\MySQL
* @author Smiley <[email protected]>
* @copyright 2017 Smiley
* @license MIT
*/
namespace chillerlan\Database\Query\Dialects\MySQL;
use chillerlan\Database\Query\{CreateDatabaseAbstract, QueryException};
class CreateDatabase extends CreateDatabaseAbstract{
protected $collate = 'utf8mb4_bin';
public function sql():string{
if(empty($this->name)){
throw new QueryException('no name specified');
}
list($charset) = explode('_', $this->collate);
$collate = 'CHARACTER SET '.$charset;
if($charset !== $this->collate){
$collate .= ' COLLATE '.$this->collate;
$sql = 'CREATE DATABASE ';
$sql .= $this->ifNotExists ? 'IF NOT EXISTS ' : '';
$sql .= $this->quote($this->name);
$sql .= $this->collate ? ' '.$collate : '';
return $sql;