Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Polyfills are provided for:
- the `CURL_HTTP_VERSION_3` and `CURL_HTTP_VERSION_3ONLY` constants introduced in PHP 8.4;
- the `grapheme_str_split` function introduced in PHP 8.4;
- the `bcdivmod` function introduced in PHP 8.4;
- the `PDO` driver specific sub-classes introduced in PHP 8.4;
- the `get_error_handler` and `get_exception_handler` functions introduced in PHP 8.5;
- the `NoDiscard` attribute introduced in PHP 8.5;
- the `array_first` and `array_last` functions introduced in PHP 8.5;
Expand Down
1 change: 1 addition & 0 deletions src/Php84/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This component provides features added to PHP 8.4 core:
- [`grapheme_str_split`](https://wiki.php.net/rfc/grapheme_str_split)
- [`mb_trim`, `mb_ltrim` and `mb_rtrim`](https://wiki.php.net/rfc/mb_trim)
- [`mb_ucfirst` and `mb_lcfirst`](https://wiki.php.net/rfc/mb_ucfirst)
- [`PDO` driver specific sub-classes](https://wiki.php.net/rfc/pdo_driver_specific_subclasses)
- [`ReflectionConstant`](https://github.com/php/php-src/pull/13669)

More information can be found in the
Expand Down
48 changes: 48 additions & 0 deletions src/Php84/Resources/stubs/Pdo/Dblib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pdo;

use PDO;
use PDOException;

if (\PHP_VERSION_ID < 80400 && extension_loaded('pdo_dblib')) {
class Dblib extends PDO
{
public const ATTR_CONNECTION_TIMEOUT = PDO::DBLIB_ATTR_CONNECTION_TIMEOUT;
public const ATTR_QUERY_TIMEOUT = PDO::DBLIB_ATTR_QUERY_TIMEOUT;
public const ATTR_STRINGIFY_UNIQUEIDENTIFIER = PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER;
public const ATTR_VERSION = PDO::DBLIB_ATTR_VERSION;
public const ATTR_TDS_VERSION = \PHP_VERSION_ID >= 70300 ? PDO::DBLIB_ATTR_TDS_VERSION : 1004;
public const ATTR_SKIP_EMPTY_ROWSETS = \PHP_VERSION_ID >= 70300 ? PDO::DBLIB_ATTR_SKIP_EMPTY_ROWSETS : 1005;
public const ATTR_DATETIME_CONVERT = \PHP_VERSION_ID >= 70300 ? \PDO::DBLIB_ATTR_DATETIME_CONVERT : 1006;

public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)
{
parent::__construct($dsn, $username, $password, $options);

if ('dblib' !== $driver = $this->getAttribute(PDO::ATTR_DRIVER_NAME))
{
throw new PDOException(\sprintf('Pdo\Dblib::__construct() cannot be used for connecting to the "%s" driver', $driver));
}
}

public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self
{
try {
return new self($dsn, $username, $password, $options);
} catch (PDOException $e) {
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;
}
}
}
}
44 changes: 44 additions & 0 deletions src/Php84/Resources/stubs/Pdo/Firebird.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pdo;

use PDO;
use PDOException;

if (\PHP_VERSION_ID < 80400 && extension_loaded('pdo_firebird')) {
class Firebird extends PDO
{
public const ATTR_DATE_FORMAT = PDO::FB_ATTR_DATE_FORMAT;
public const ATTR_TIME_FORMAT = PDO::FB_ATTR_TIME_FORMAT;
public const ATTR_TIMESTAMP_FORMAT = PDO::FB_ATTR_TIMESTAMP_FORMAT;

public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)
{
parent::__construct($dsn, $username, $password, $options);

if ('firebird' !== $driver = $this->getAttribute(PDO::ATTR_DRIVER_NAME))
{
throw new PDOException(\sprintf('Pdo\Firebird::__construct() cannot be used for connecting to the "%s" driver', $driver));
}
}

public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self
{
try {
return new self($dsn, $username, $password, $options);
} catch (PDOException $e) {
throw preg_match('/^Pdo\\\\Firebird::__construct\(\) cannot be used for connecting to the "([a-z]+)" driver/', $e->getMessage(), $matches)
? new PDOException(\sprintf('Pdo\Firebird::connect() cannot be used for connecting to the "%s" driver', $matches[1]))
: $e;
}
}
}
}
108 changes: 108 additions & 0 deletions src/Php84/Resources/stubs/Pdo/Mysql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pdo;

use PDO;
use PDOException;

if (\PHP_VERSION_ID < 80400 && extension_loaded('pdo_mysql')) {
// Feature detection for non-mysqlnd; see also https://www.php.net/manual/en/class.pdo-mysql.php#pdo-mysql.constants.attr-max-buffer-size
if (defined('PDO::MYSQL_ATTR_MAX_BUFFER_SIZE') && defined('PDO::MYSQL_ATTR_READ_DEFAULT_FILE') && defined('PDO::MYSQL_ATTR_READ_DEFAULT_GROUP'))
{
class Mysql extends PDO
{
public const ATTR_COMPRESS = PDO::MYSQL_ATTR_COMPRESS;
public const ATTR_DIRECT_QUERY = PDO::MYSQL_ATTR_DIRECT_QUERY;
public const ATTR_FOUND_ROWS = PDO::MYSQL_ATTR_FOUND_ROWS;
public const ATTR_IGNORE_SPACE = PDO::MYSQL_ATTR_IGNORE_SPACE;
public const ATTR_INIT_COMMAND = PDO::MYSQL_ATTR_INIT_COMMAND;
public const ATTR_LOCAL_INFILE = PDO::MYSQL_ATTR_LOCAL_INFILE;
public const ATTR_LOCAL_INFILE_DIRECTORY = \PHP_VERSION_ID >= 80100 ? \PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY : 1015;
public const ATTR_MAX_BUFFER_SIZE = PDO::MYSQL_ATTR_MAX_BUFFER_SIZE;
public const ATTR_MULTI_STATEMENTS = PDO::MYSQL_ATTR_MULTI_STATEMENTS;
public const ATTR_READ_DEFAULT_FILE = PDO::MYSQL_ATTR_READ_DEFAULT_FILE;
public const ATTR_READ_DEFAULT_GROUP = PDO::MYSQL_ATTR_READ_DEFAULT_GROUP;
public const ATTR_SERVER_PUBLIC_KEY = PDO::MYSQL_ATTR_SERVER_PUBLIC_KEY;
public const ATTR_SSL_CA = PDO::MYSQL_ATTR_SSL_CA;
public const ATTR_SSL_CAPATH = PDO::MYSQL_ATTR_SSL_CAPATH;
public const ATTR_SSL_CERT = PDO::MYSQL_ATTR_SSL_CERT;
public const ATTR_SSL_CIPHER = PDO::MYSQL_ATTR_SSL_CIPHER;
public const ATTR_SSL_KEY = PDO::MYSQL_ATTR_SSL_KEY;
public const ATTR_SSL_VERIFY_SERVER_CERT = PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT;
public const ATTR_USE_BUFFERED_QUERY = PDO::MYSQL_ATTR_USE_BUFFERED_QUERY;

public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)
{
parent::__construct($dsn, $username, $password, $options);

if ('mysql' !== $driver = $this->getAttribute(PDO::ATTR_DRIVER_NAME))
{
throw new PDOException(\sprintf('Pdo\Mysql::__construct() cannot be used for connecting to the "%s" driver', $driver));
}
}

public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self
{
try {
return new self($dsn, $username, $password, $options);
} catch (PDOException $e) {
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;
}
}
}
} else {
class Mysql extends PDO
{
public const ATTR_COMPRESS = PDO::MYSQL_ATTR_COMPRESS;
public const ATTR_DIRECT_QUERY = PDO::MYSQL_ATTR_DIRECT_QUERY;
public const ATTR_FOUND_ROWS = PDO::MYSQL_ATTR_FOUND_ROWS;
public const ATTR_IGNORE_SPACE = PDO::MYSQL_ATTR_IGNORE_SPACE;
public const ATTR_INIT_COMMAND = PDO::MYSQL_ATTR_INIT_COMMAND;
public const ATTR_LOCAL_INFILE = PDO::MYSQL_ATTR_LOCAL_INFILE;
public const ATTR_LOCAL_INFILE_DIRECTORY = \PHP_VERSION_ID >= 80100 ? \PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY : 1015;
// public const ATTR_MAX_BUFFER_SIZE = PDO::MYSQL_ATTR_MAX_BUFFER_SIZE; // disabled for mysqlnd
public const ATTR_MULTI_STATEMENTS = PDO::MYSQL_ATTR_MULTI_STATEMENTS;
// public const ATTR_READ_DEFAULT_FILE = PDO::MYSQL_ATTR_READ_DEFAULT_FILE; // disabled for mysqlnd
// public const ATTR_READ_DEFAULT_GROUP = PDO::MYSQL_ATTR_READ_DEFAULT_GROUP; // disabled for mysqlnd
public const ATTR_SERVER_PUBLIC_KEY = PDO::MYSQL_ATTR_SERVER_PUBLIC_KEY;
public const ATTR_SSL_CA = PDO::MYSQL_ATTR_SSL_CA;
public const ATTR_SSL_CAPATH = PDO::MYSQL_ATTR_SSL_CAPATH;
public const ATTR_SSL_CERT = PDO::MYSQL_ATTR_SSL_CERT;
public const ATTR_SSL_CIPHER = PDO::MYSQL_ATTR_SSL_CIPHER;
public const ATTR_SSL_KEY = PDO::MYSQL_ATTR_SSL_KEY;
public const ATTR_SSL_VERIFY_SERVER_CERT = PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT;
public const ATTR_USE_BUFFERED_QUERY = PDO::MYSQL_ATTR_USE_BUFFERED_QUERY;

public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)
{
parent::__construct($dsn, $username, $password, $options);

if ('mysql' !== $driver = $this->getAttribute(PDO::ATTR_DRIVER_NAME))
{
throw new PDOException(\sprintf('Pdo\Mysql::__construct() cannot be used for connecting to the "%s" driver', $driver));
}
}

public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self
{
try {
return new self($dsn, $username, $password, $options);
} catch (PDOException $e) {
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;
}
}
}
}
}
46 changes: 46 additions & 0 deletions src/Php84/Resources/stubs/Pdo/Odbc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pdo;

use PDO;
use PDOException;

if (\PHP_VERSION_ID < 80400 && extension_loaded('pdo_odbc')) {
class Odbc extends PDO
{
public const ATTR_USE_CURSOR_LIBRARY = PDO::ODBC_ATTR_USE_CURSOR_LIBRARY;
public const ATTR_ASSUME_UTF8 = PDO::ODBC_ATTR_ASSUME_UTF8;
public const SQL_USE_IF_NEEDED = PDO::ODBC_SQL_USE_IF_NEEDED;
public const SQL_USE_DRIVER = PDO::ODBC_SQL_USE_DRIVER;
public const SQL_USE_ODBC = PDO::ODBC_SQL_USE_ODBC;

public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)
{
parent::__construct($dsn, $username, $password, $options);

if ('odbc' !== $driver = $this->getAttribute(PDO::ATTR_DRIVER_NAME))
{
throw new PDOException(\sprintf('Pdo\Odbc::__construct() cannot be used for connecting to the "%s" driver', $driver));
}
}

public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self
{
try {
return new self($dsn, $username, $password, $options);
} catch (PDOException $e) {
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;
}
}
}
}
99 changes: 99 additions & 0 deletions src/Php84/Resources/stubs/Pdo/Pgsql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pdo;

use PDO;
use PDOException;

if (\PHP_VERSION_ID < 80400 && extension_loaded('pdo_pgsql')) {
class Pgsql extends PDO
{
public const ATTR_DISABLE_PREPARES = PDO::PGSQL_ATTR_DISABLE_PREPARES;

public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)
{
parent::__construct($dsn, $username, $password, $options);

if ('pgsql' !== $driver = $this->getAttribute(PDO::ATTR_DRIVER_NAME))
{
throw new PDOException(\sprintf('Pdo\Pgsql::__construct() cannot be used for connecting to the "%s" driver', $driver));
}
}

public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self
{
try {
return new self($dsn, $username, $password, $options);
} catch (PDOException $e) {
throw preg_match('/^Pdo\\\\Pgsql::__construct\(\) cannot be used for connecting to the "([a-z]+)" driver/', $e->getMessage(), $matches)
? new PDOException(\sprintf('Pdo\Pgsql::connect() cannot be used for connecting to the "%s" driver', $matches[1]))
: $e;
}
}

public function copyFromArray(string $tableName, array $rows, string $separator = "\t", string $nullAs = "\\\\N", ?string $fields = null): bool
{
return $this->pgsqlCopyFromArray($tableName, $rows, $separator, $nullAs, $fields);
}

public function copyFromFile(string $tableName, string $filename, string $separator = "\t", string $nullAs = "\\\\N", ?string $fields = null): bool
{
return $this->pgsqlCopyFromFile($tableName, $filename, $separator, $nullAs, $fields);
}

/**
* @return array|false
*/
public function copyToArray(string $tableName, string $separator = "\t", string $nullAs = "\\\\N", ?string $fields = null)
{
return $this->pgsqlCopyToArray($tableName, $separator, $nullAs, $fields);
}

public function copyToFile(string $tableName, string $filename, string $separator = "\t", string $nullAs = "\\\\N", ?string $fields = null): bool
{
return $this->pgsqlCopyToFile($tableName, $filename, $separator, $nullAs, $fields);
}

/**
* @return array|false
*/
public function getNotify(int $fetchMode = PDO::FETCH_DEFAULT, int $timeoutMilliseconds = 0)
{
return $this->pgsqlGetNotify($fetchMode, $timeoutMilliseconds);
}

public function getPid(): int
{
return $this->pgsqlGetPid();
}

/**
* @return string|false
*/
public function lobCreate()
{
return $this->pgsqlLOBCreate();
}

/**
* @return resource|false
*/
public function lobOpen(string $oid, string $mode = "rb")
{
return $this->pgsqlLOBOpen($oid, $mode);
}

public function lobUnlink(string $oid): bool
{
return $this->pgsqlLOBUnlink($oid);
}
}
}
Loading
Loading