| 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 |
use PDO; |
| 15 |
|
| 16 |
if (\PHP_VERSION_ID < 80400 && \extension_loaded('pdo_mysql')) { |
| 17 |
// Feature detection for non-mysqlnd; see also https://www.php.net/manual/en/class.pdo-mysql.php#pdo-mysql.constants.attr-max-buffer-size |
| 18 |
if (\defined('PDO::MYSQL_ATTR_MAX_BUFFER_SIZE') && \defined('PDO::MYSQL_ATTR_READ_DEFAULT_FILE') && \defined('PDO::MYSQL_ATTR_READ_DEFAULT_GROUP')) { |
| 19 |
class Mysql extends \PDO |
| 20 |
{ |
| 21 |
public const ATTR_COMPRESS = \PDO::MYSQL_ATTR_COMPRESS; |
| 22 |
public const ATTR_DIRECT_QUERY = \PDO::MYSQL_ATTR_DIRECT_QUERY; |
| 23 |
public const ATTR_FOUND_ROWS = \PDO::MYSQL_ATTR_FOUND_ROWS; |
| 24 |
public const ATTR_IGNORE_SPACE = \PDO::MYSQL_ATTR_IGNORE_SPACE; |
| 25 |
public const ATTR_INIT_COMMAND = \PDO::MYSQL_ATTR_INIT_COMMAND; |
| 26 |
public const ATTR_LOCAL_INFILE = \PDO::MYSQL_ATTR_LOCAL_INFILE; |
| 27 |
public const ATTR_LOCAL_INFILE_DIRECTORY = \PHP_VERSION_ID >= 80100 ? \PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY : 1015; |
| 28 |
public const ATTR_MAX_BUFFER_SIZE = \PDO::MYSQL_ATTR_MAX_BUFFER_SIZE; |
| 29 |
public const ATTR_MULTI_STATEMENTS = \PDO::MYSQL_ATTR_MULTI_STATEMENTS; |
| 30 |
public const ATTR_READ_DEFAULT_FILE = \PDO::MYSQL_ATTR_READ_DEFAULT_FILE; |
| 31 |
public const ATTR_READ_DEFAULT_GROUP = \PDO::MYSQL_ATTR_READ_DEFAULT_GROUP; |
| 32 |
public const ATTR_SERVER_PUBLIC_KEY = \PDO::MYSQL_ATTR_SERVER_PUBLIC_KEY; |
| 33 |
public const ATTR_SSL_CA = \PDO::MYSQL_ATTR_SSL_CA; |
| 34 |
public const ATTR_SSL_CAPATH = \PDO::MYSQL_ATTR_SSL_CAPATH; |
| 35 |
public const ATTR_SSL_CERT = \PDO::MYSQL_ATTR_SSL_CERT; |
| 36 |
public const ATTR_SSL_CIPHER = \PDO::MYSQL_ATTR_SSL_CIPHER; |
| 37 |
public const ATTR_SSL_KEY = \PDO::MYSQL_ATTR_SSL_KEY; |
| 38 |
public const ATTR_SSL_VERIFY_SERVER_CERT = \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT; |
| 39 |
public const ATTR_USE_BUFFERED_QUERY = \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY; |
| 40 |
|
| 41 |
public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null) |
| 42 |
{ |
| 43 |
parent::__construct($dsn, $username, $password, $options); |
| 44 |
|
| 45 |
if ('mysql' !== $driver = $this->getAttribute(\PDO::ATTR_DRIVER_NAME)) { |
| 46 |
throw new \PDOException(\sprintf('Pdo\Mysql::__construct() cannot be used for connecting to the "%s" driver', $driver)); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self |
| 51 |
{ |
| 52 |
try { |
| 53 |
return new self($dsn, $username, $password, $options); |
| 54 |
} catch (\PDOException $e) { |
| 55 |
throw preg_match('/^Pdo\\\\Mysql::__construct\(\) cannot be used for connecting to the "([a-z]+)" driver/', $e->getMessage(), $matches) ? new \PDOException(\sprintf('Pdo\Mysql::connect() cannot be used for connecting to the "%s" driver', $matches[1])) : $e; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
} else { |
| 60 |
class Mysql extends \PDO |
| 61 |
{ |
| 62 |
public const ATTR_COMPRESS = \PDO::MYSQL_ATTR_COMPRESS; |
| 63 |
public const ATTR_DIRECT_QUERY = \PDO::MYSQL_ATTR_DIRECT_QUERY; |
| 64 |
public const ATTR_FOUND_ROWS = \PDO::MYSQL_ATTR_FOUND_ROWS; |
| 65 |
public const ATTR_IGNORE_SPACE = \PDO::MYSQL_ATTR_IGNORE_SPACE; |
| 66 |
public const ATTR_INIT_COMMAND = \PDO::MYSQL_ATTR_INIT_COMMAND; |
| 67 |
public const ATTR_LOCAL_INFILE = \PDO::MYSQL_ATTR_LOCAL_INFILE; |
| 68 |
public const ATTR_LOCAL_INFILE_DIRECTORY = \PHP_VERSION_ID >= 80100 ? \PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY : 1015; |
| 69 |
// public const ATTR_MAX_BUFFER_SIZE = PDO::MYSQL_ATTR_MAX_BUFFER_SIZE; // disabled for mysqlnd |
| 70 |
public const ATTR_MULTI_STATEMENTS = \PDO::MYSQL_ATTR_MULTI_STATEMENTS; |
| 71 |
// public const ATTR_READ_DEFAULT_FILE = PDO::MYSQL_ATTR_READ_DEFAULT_FILE; // disabled for mysqlnd |
| 72 |
// public const ATTR_READ_DEFAULT_GROUP = PDO::MYSQL_ATTR_READ_DEFAULT_GROUP; // disabled for mysqlnd |
| 73 |
public const ATTR_SERVER_PUBLIC_KEY = \PDO::MYSQL_ATTR_SERVER_PUBLIC_KEY; |
| 74 |
public const ATTR_SSL_CA = \PDO::MYSQL_ATTR_SSL_CA; |
| 75 |
public const ATTR_SSL_CAPATH = \PDO::MYSQL_ATTR_SSL_CAPATH; |
| 76 |
public const ATTR_SSL_CERT = \PDO::MYSQL_ATTR_SSL_CERT; |
| 77 |
public const ATTR_SSL_CIPHER = \PDO::MYSQL_ATTR_SSL_CIPHER; |
| 78 |
public const ATTR_SSL_KEY = \PDO::MYSQL_ATTR_SSL_KEY; |
| 79 |
public const ATTR_SSL_VERIFY_SERVER_CERT = \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT; |
| 80 |
public const ATTR_USE_BUFFERED_QUERY = \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY; |
| 81 |
|
| 82 |
public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null) |
| 83 |
{ |
| 84 |
parent::__construct($dsn, $username, $password, $options); |
| 85 |
|
| 86 |
if ('mysql' !== $driver = $this->getAttribute(\PDO::ATTR_DRIVER_NAME)) { |
| 87 |
throw new \PDOException(\sprintf('Pdo\Mysql::__construct() cannot be used for connecting to the "%s" driver', $driver)); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self |
| 92 |
{ |
| 93 |
try { |
| 94 |
return new self($dsn, $username, $password, $options); |
| 95 |
} catch (\PDOException $e) { |
| 96 |
throw preg_match('/^Pdo\\\\Mysql::__construct\(\) cannot be used for connecting to the "([a-z]+)" driver/', $e->getMessage(), $matches) ? new \PDOException(\sprintf('Pdo\Mysql::connect() cannot be used for connecting to the "%s" driver', $matches[1])) : $e; |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
} |