https://github.com/php-polyfills/pdo-mysql-subclass
User-land PHP polyfill for PDO MySQL driver subclass
https://github.com/php-polyfills/pdo-mysql-subclass
compat mysql pdo php php8 php84 polyfills
Last synced: about 2 months ago
JSON representation
User-land PHP polyfill for PDO MySQL driver subclass
- Host: GitHub
- URL: https://github.com/php-polyfills/pdo-mysql-subclass
- Owner: PHP-Polyfills
- License: mit
- Created: 2024-01-12T10:20:59.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-14T17:28:43.000Z (about 2 years ago)
- Last Synced: 2025-07-19T09:58:32.608Z (8 months ago)
- Topics: compat, mysql, pdo, php, php8, php84, polyfills
- Language: PHP
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PDO MySQL Subclass Polyfill
[](https://packagist.org/packages/polyfills/pdo-mysql-subclass) [](https://packagist.org/packages/polyfills/pdo-mysql-subclass) [](https://packagist.org/packages/polyfills/pdo-mysql-subclass) 
Provides user-land PHP polyfills for the MySQL subclass provided by PHP 8.4.
Supports PHP 8.1, 8.2, and 8.3. On PHP 8.4 and later, this polyfill is not necessary. Requires `pdo_mysql` extension compiled with `mysqlnd` (which is the default and common approach).
It is possible and safe to require this polyfill on PHP 8.4 and later. This polyfill class is autoloadable; on PHP 8.4 and later, PHP will _not_ autoload this polyfill because it's declared natively.
For more information, see [`PdoMysql`](https://php.watch/versions/8.4/pdo-driver-subclasses#PdoMysql) on [`PHP 8.4: PDO Driver-specific sub-classes: MySQL`](https://php.watch/versions/8.4/pdo-driver-subclasses)
## Installation
```bash
composer require polyfills/pdo-mysql-subclass
```
## Usage
Use the provided `PdoMysql` class to replace `PDO` MySQL connections.
```php
$mysqlConnection = new PdoMysql(
'mysql:host=localhost;dbname=phpwatch;charset=utf8mb4;port=33066',
'',
'',
);
```
```php
$mysqlConnection = PdoMysql::connect(
'mysql:host=localhost;dbname=phpwatch;charset=utf8mb4;port=33066',
'',
'',
);
```
This polyfill adds class-constants to `PdoMysql` class to match all of the `PDO::MYSQL_` constants. For example, `PDO::MYSQL_ATTR_SSL_CERT` is identical to `PdoMysql::ATTR_SSL_CERT`.
### Features not implemented
- `PDO::connect`: This method cannot be polyfilled because it's an existing PHP class that user-land PHP classes cannot modify.
- `PdoMysql::getWarningCount`: This method is not implemented in the polfyill.
## Contributions
Contributions are welcome either as a GitHub issue or a PR to this repo.