Skip to content

Commit

Permalink
[10.x] Fix optional charset and collation when creating database (#50168
Browse files Browse the repository at this point in the history
)

* Fix optional charset and collation when creating database

* Update MySqlGrammar.php

* Re-use the var i made for this
  • Loading branch information
GrahamCampbell authored Feb 21, 2024
1 parent f7c57c4 commit e550f2b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ class MySqlGrammar extends Grammar
*/
public function compileCreateDatabase($name, $connection)
{
$charset = $connection->getConfig('charset');
$collation = $connection->getConfig('collation');

if (! $charset || ! $collation) {
return sprintf(
'create database %s',
$this->wrapValue($name),
);
}

return sprintf(
'create database %s default character set %s default collate %s',
$this->wrapValue($name),
$this->wrapValue($connection->getConfig('charset')),
$this->wrapValue($connection->getConfig('collation')),
$this->wrapValue($charset),
$this->wrapValue($collation),
);
}

Expand Down

0 comments on commit e550f2b

Please sign in to comment.