Debian Codegraph @

vendor/symfony/polyfill-php84/Resources/stubs/Pdo/Odbc.php

raw
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_odbc')) {
15 class Odbc extends \PDO
16 {
17 public const ATTR_USE_CURSOR_LIBRARY = \PDO::ODBC_ATTR_USE_CURSOR_LIBRARY;
18 public const ATTR_ASSUME_UTF8 = \PDO::ODBC_ATTR_ASSUME_UTF8;
19 public const SQL_USE_IF_NEEDED = \PDO::ODBC_SQL_USE_IF_NEEDED;
20 public const SQL_USE_DRIVER = \PDO::ODBC_SQL_USE_DRIVER;
21 public const SQL_USE_ODBC = \PDO::ODBC_SQL_USE_ODBC;
22
23 public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)
24 {
25 parent::__construct($dsn, $username, $password, $options);
26
27 if ('odbc' !== $driver = $this->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
28 throw new \PDOException(\sprintf('Pdo\Odbc::__construct() cannot be used for connecting to the "%s" driver', $driver));
29 }
30 }
31
32 public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self
33 {
34 try {
35 return new self($dsn, $username, $password, $options);
36 } catch (\PDOException $e) {
37 throw preg_match('/^Pdo\\\\Odbc::__construct\(\) cannot be used for connecting to the "([a-z]+)" driver/', $e->getMessage(), $matches) ? new \PDOException(\sprintf('Pdo\Odbc::connect() cannot be used for connecting to the "%s" driver', $matches[1])) : $e;
38 }
39 }
40 }
41 }