summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php')
-rw-r--r--vendor/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php b/vendor/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php
new file mode 100644
index 0000000..778ea64
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php
@@ -0,0 +1,41 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Driver\Mysqli\Exception;
6
7use Doctrine\DBAL\Driver\AbstractException;
8use mysqli;
9use mysqli_sql_exception;
10use ReflectionProperty;
11
12use function sprintf;
13
14/**
15 * @internal
16 *
17 * @psalm-immutable
18 */
19final class InvalidCharset extends AbstractException
20{
21 public static function fromCharset(mysqli $connection, string $charset): self
22 {
23 return new self(
24 sprintf('Failed to set charset "%s": %s', $charset, $connection->error),
25 $connection->sqlstate,
26 $connection->errno,
27 );
28 }
29
30 public static function upcast(mysqli_sql_exception $exception, string $charset): self
31 {
32 $p = new ReflectionProperty(mysqli_sql_exception::class, 'sqlstate');
33
34 return new self(
35 sprintf('Failed to set charset "%s": %s', $charset, $exception->getMessage()),
36 $p->getValue($exception),
37 $exception->getCode(),
38 $exception,
39 );
40 }
41}