1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 17:44:04 +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:
lukinovec 2026-05-04 11:15:51 +02:00
parent ea20eb13b6
commit 405aaafb4e
2 changed files with 85 additions and 1 deletions

View file

@ -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