mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-07 01:04:03 +00:00
Handle MySQL charset and collation
Make createDatabase execute CREATE DATABASE without passing charset and collation so that if these parameters are null, the MySQL server's defaults will be used. Only add charset and collation to the statement if they're not null.
This commit is contained in:
parent
ea20eb13b6
commit
405aaafb4e
2 changed files with 85 additions and 1 deletions
|
|
@ -16,7 +16,21 @@ class MySQLDatabaseManager extends TenantDatabaseManager
|
|||
|
||||
$this->validateParameter([$database, $charset, $collation]);
|
||||
|
||||
return $this->connection()->statement("CREATE DATABASE `{$database}` CHARACTER SET `$charset` COLLATE `$collation`");
|
||||
// MySQL defaults to the server's charset and collation
|
||||
// if charset and collation are not specified.
|
||||
// If charset is specified but collation is null, MySQL
|
||||
// will choose a default collation for the specified charset (and vice versa).
|
||||
$statement = "CREATE DATABASE `{$database}`";
|
||||
|
||||
if ($charset !== null) {
|
||||
$statement .= " CHARACTER SET `{$charset}`";
|
||||
}
|
||||
|
||||
if ($collation !== null) {
|
||||
$statement .= " COLLATE `{$collation}`";
|
||||
}
|
||||
|
||||
return $this->connection()->statement($statement);
|
||||
}
|
||||
|
||||
public function deleteDatabase(TenantWithDatabase $tenant): bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue