diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/Mysqli/Initializer/Charset.php')
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/Mysqli/Initializer/Charset.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/Mysqli/Initializer/Charset.php b/vendor/doctrine/dbal/src/Driver/Mysqli/Initializer/Charset.php new file mode 100644 index 0000000..d02c768 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/Mysqli/Initializer/Charset.php | |||
@@ -0,0 +1,32 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\Mysqli\Initializer; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\Mysqli\Exception\InvalidCharset; | ||
8 | use Doctrine\DBAL\Driver\Mysqli\Initializer; | ||
9 | use mysqli; | ||
10 | use mysqli_sql_exception; | ||
11 | |||
12 | final class Charset implements Initializer | ||
13 | { | ||
14 | public function __construct(private readonly string $charset) | ||
15 | { | ||
16 | } | ||
17 | |||
18 | public function initialize(mysqli $connection): void | ||
19 | { | ||
20 | try { | ||
21 | $success = $connection->set_charset($this->charset); | ||
22 | } catch (mysqli_sql_exception $e) { | ||
23 | throw InvalidCharset::upcast($e, $this->charset); | ||
24 | } | ||
25 | |||
26 | if ($success) { | ||
27 | return; | ||
28 | } | ||
29 | |||
30 | throw InvalidCharset::fromCharset($connection, $this->charset); | ||
31 | } | ||
32 | } | ||