| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Pdo; |
| 13 |
|
| 14 |
if (\PHP_VERSION_ID < 80400 && \extension_loaded('pdo_dblib')) { |
| 15 |
class Dblib extends \PDO |
| 16 |
{ |
| 17 |
public const ATTR_CONNECTION_TIMEOUT = \PDO::DBLIB_ATTR_CONNECTION_TIMEOUT; |
| 18 |
public const ATTR_QUERY_TIMEOUT = \PDO::DBLIB_ATTR_QUERY_TIMEOUT; |
| 19 |
public const ATTR_STRINGIFY_UNIQUEIDENTIFIER = \PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER; |
| 20 |
public const ATTR_VERSION = \PDO::DBLIB_ATTR_VERSION; |
| 21 |
public const ATTR_TDS_VERSION = \PHP_VERSION_ID >= 70300 ? \PDO::DBLIB_ATTR_TDS_VERSION : 1004; |
| 22 |
public const ATTR_SKIP_EMPTY_ROWSETS = \PHP_VERSION_ID >= 70300 ? \PDO::DBLIB_ATTR_SKIP_EMPTY_ROWSETS : 1005; |
| 23 |
public const ATTR_DATETIME_CONVERT = \PHP_VERSION_ID >= 70300 ? \PDO::DBLIB_ATTR_DATETIME_CONVERT : 1006; |
| 24 |
|
| 25 |
public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null) |
| 26 |
{ |
| 27 |
parent::__construct($dsn, $username, $password, $options); |
| 28 |
|
| 29 |
if ('dblib' !== $driver = $this->getAttribute(\PDO::ATTR_DRIVER_NAME)) { |
| 30 |
throw new \PDOException(\sprintf('Pdo\Dblib::__construct() cannot be used for connecting to the "%s" driver', $driver)); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self |
| 35 |
{ |
| 36 |
try { |
| 37 |
return new self($dsn, $username, $password, $options); |
| 38 |
} catch (\PDOException $e) { |
| 39 |
throw preg_match('/^Pdo\\\\Dblib::__construct\(\) cannot be used for connecting to the "([a-z]+)" driver/', $e->getMessage(), $matches) ? new \PDOException(\sprintf('Pdo\Dblib::connect() cannot be used for connecting to the "%s" driver', $matches[1])) : $e; |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |