summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Platforms/MySQL/CharsetMetadataProvider/ConnectionCharsetMetadataProvider.php
blob: 65b63df8fe669fbfa7ec43e405d48b786bc52cc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Platforms\MySQL\CharsetMetadataProvider;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQL\CharsetMetadataProvider;

/** @internal */
final class ConnectionCharsetMetadataProvider implements CharsetMetadataProvider
{
    public function __construct(private readonly Connection $connection)
    {
    }

    /** @throws Exception */
    public function getDefaultCharsetCollation(string $charset): ?string
    {
        $collation = $this->connection->fetchOne(
            <<<'SQL'
            SELECT DEFAULT_COLLATE_NAME
            FROM information_schema.CHARACTER_SETS
            WHERE CHARACTER_SET_NAME = ?;
            SQL
            ,
            [$charset],
        );

        if ($collation !== false) {
            return $collation;
        }

        return null;
    }
}