- Version: 0.9
- Date: 2022-06-04
- Author: Danack
- Status: Draft
- First Published at: http://wiki.php.net/rfc/PDOSubclasses
PDO is a generic database class. Some of the databases it supports have functionality that is specific to that database.
For example, when connected to an SQLite database, the sqlite specific function PDO::sqliteCreateFunction is available.
This is a slightly terrible way of doing things. And is an example of code that was snuck in before the RFC process was in place.
This RFC continues a discussion on internals of reimplementing this functionality 'properly'.
The proposal has three parts:
- Add new subclasses of PDO
- Add PDO::connect to be able to create them
- Add DB specific function to those subclasses.
There will be one subclasses for each known PDO support DB connection:
- PDODblib
- PDOFirebird
- PDOMysql
- PDOOci
- PDOOdbc
- PDOPgsql - definitely
- PDOSqlite - definitely
Each of these subclasses will expose functionality that exists that is peculiar to that DB, and not present in the generic PDO class. e.g. PDOSqlite::createFunction() should be there rather than on PDO::sqliteCreateFunction.
Add a static factory method to PDO called connect
. During the connect process, the exact type of database being connected to will be checked, and if it is a DB that has a specific sub-class, return that sub-class instead of a generic PDO object
class PDO
{
public static function connect(string $dsn [, string $username [, string $password [, array $options ]]]) {
if (connecting to SQLite DB) {
return new PDOSqlite(...);
}
return new PDO(...);
}
}
PDO::connect will return the appropriate sub-class when connecting to specific type of DB.
None known. It might be inconvenient for people who are extending PDO class directly, and would like to extend the specific types. They would need to write their own connect functions, that wrap and proxy those specific types.
PHP 8.2
There are the known current issues.
e.g. should PDOSqlite exist if PHP was compiled without PDO_SQLITE compilted in? Probaby not.
Should all DBs have sub-classes created now, or should they be added when someone requests it?
The method PDO::sqliteCreateFunction should probably be deprecated and removed at 'some point'. Although this cleanup should happen, the position of this RFC is that it's very low priority.
8.2 - PDO subclassses become available 9.0 - calls to PDO::sqliteCreateFunction start raising deprecation notice. 10.0 - method PDO::sqliteCreateFunction is removed, and that functionality can only be accessed through PDOSqlite
Removing the methods that magically exist or not depending on the specific driver created would save some complication in the PDO code. So although there's not benefit in userland for deprecating the existing magic methods, there may be a complexity saving in maintenance.
Everything else
Any DB specific stuff known about that were too much work to implement?
Accept the RFC as proposed 2/3 required.
Links to any external patches and tests go here.
After the project is implemented, this section should contain
- the version(s) it was merged into
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
- a link to the language specification section (if any)
Links to external references, discussions or RFCs
Keep this updated with features that were discussed on the mail lists.