Skip to content

Commit e550f2b

Browse files
[10.x] Fix optional charset and collation when creating database (#50168)
* Fix optional charset and collation when creating database * Update MySqlGrammar.php * Re-use the var i made for this
1 parent f7c57c4 commit e550f2b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,21 @@ class MySqlGrammar extends Grammar
4343
*/
4444
public function compileCreateDatabase($name, $connection)
4545
{
46+
$charset = $connection->getConfig('charset');
47+
$collation = $connection->getConfig('collation');
48+
49+
if (! $charset || ! $collation) {
50+
return sprintf(
51+
'create database %s',
52+
$this->wrapValue($name),
53+
);
54+
}
55+
4656
return sprintf(
4757
'create database %s default character set %s default collate %s',
4858
$this->wrapValue($name),
49-
$this->wrapValue($connection->getConfig('charset')),
50-
$this->wrapValue($connection->getConfig('collation')),
59+
$this->wrapValue($charset),
60+
$this->wrapValue($collation),
5161
);
5262
}
5363

0 commit comments

Comments
 (0)