Skip to content

Commit

Permalink
Introduce MySQLi Connection initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jun 24, 2020
1 parent 1ee8cf3 commit 383d304
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
27 changes: 27 additions & 0 deletions lib/Doctrine/DBAL/Driver/Mysqli/Exception/InvalidOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver\Mysqli\Exception;

use Doctrine\DBAL\Driver\Mysqli\MysqliException;

use function sprintf;

/**
* @internal
*
* @psalm-immutable
*/
final class InvalidOption extends MysqliException
{
/**
* @param mixed $value
*/
public static function fromOption(int $option, $value): self
{
return new self(
sprintf('Failed to set option %d with value "%s"', $option, $value)
);
}
}
5 changes: 2 additions & 3 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Driver\Mysqli;

use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
use Doctrine\DBAL\Driver\Mysqli\Exception\InvalidOption;
use Doctrine\DBAL\Driver\PingableConnection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
Expand Down Expand Up @@ -257,9 +258,7 @@ private function setDriverOptions(array $driverOptions = []): void
}

if (! in_array($option, $supportedDriverOptions, true)) {
throw new MysqliException(
sprintf($exceptionMsg, 'Unsupported', $option, $value)
);
throw InvalidOption::fromOption($option, $value);
}

if (@mysqli_options($this->conn, $option, $value)) {
Expand Down

0 comments on commit 383d304

Please sign in to comment.