This is an old revision of the document!
Thoughts and ideas about improving PDO. Wez's PDOv1 spec could be useful: http://www.php.net/~wez/pdo/pdo-spec.html
Relevant RFC
Questions
- What have we learned about the PDO architecture in the past years (that needs fixing)?
- How do we deal with features that only related to one (or few) drivers? What if its impossible to fit a similar feature under a single API? Currently we have a few driver specific attributes (like the unbuffered query attribute for MySQL).
- How do we deal with different error handling? Like some RDBMS create throw errors during the prepare stage, others at the first execute.
- How do we deal with different behavior like transaction errors causing a rollback on some RDBMS but not on others.
- How to deal with missing functionality available inside the native extensions? Is the goal to eventually replace the native extensions? Is there any chance to share connections between PDO and the native extensions?
- How do we handle cross connection transactions? ( 2 phase commit across multiple databases - need to add more information later )
PDO Bugs / PDO2 Improvements
PDO
Documentation
- FETCH_SERIALIZE description is wrong, it works like FETCH_CLASS not FETCH_INTO
- document finally remaining FETCH constants like FETCH_KEY_VALUE, FETCH_FUNC
- better document fetchAll() constants
Parameter binding & explicit data type set
- bindValue() & bindParam() should enforce the type giving, currently it uses the current zval type for MySQL Bug bug #44639 / PDO: Fixing bug #44639 for mysql
- PARAM_INT with strings => it should try to convert to the type, otherwise throw an Exception or create an error.
- PARAM_BOOLEAN with strings => Exception or Error.
- a new PARAM_AUTO could be used to determine the type by zval (old mysql behavior)
- execute() could use an automatic approach PARAM_AUTO, could be a BC break http://news.php.net/php.pdo/235
- allows automatic convert to PARAM_INT if zval is integer / float
- prepared statement emulation (placeholder rewriting) is fragile, cannot deal well with strings that look like placeholders inside quoted strings like “WHERE foo = 'check ?'” or serialized data
- different behavior when reusing the same oracle style named placeholder multiple times
fetchObject
- Bug#49521 “PDO fetchObject sets values before calling constructor”
- add note to FETCH_PROPS_LATE
- allow setting FETCH_PROPS_LATE or assume it as default?
Unified API meta data access
see http://news.php.net/php.pdo/233
- PDOStatement::getColumnMeta with a new parameter to get only one meta type back ml#123127892009423 wouldn't break the current api.
- META_NAME => column name
- META_TABLENAME => table name
- ...
Asynchronous requests
see http://news.php.net/php.pdo/268
For features not yet finalized:
see http://news.php.net/php.pdo/286 PDO_Driver::getNative()::asyncQuery();
Most drivers allow some kind of async query except MySQL, additional connections could be created to allow concurrent queries.
PDO Persistent Connections
see http://news.php.net/php.pdo/318 see http://news.php.net/php.pdo/319
- Defaults to be portable as much as possible
- Allow to disable certain connection reset/cleanup features to gain even more speed.
PDO2
fetchAll
- add fetchAll() FETCH_UNIQUE without FETCH_GROUP (PHP5.3 seems to support it already?)
- allow the column id to be set
- allow to receive the key column in the result
- allow with FETCH_CLASS
XML Support
Transaction
PDO transaction object see http://news.php.net/php.pdo/322
Possible problems:
- error handling
- nested transaction (emulation)
PDO Binding behaviour (5.3)
MySQL | SQLite | Firebird | ODBC | PostgreSQL | |
---|---|---|---|---|---|
PDO_PARAM_STR | zval type | convert_to_string/null | zval type/null | convert_to_string/ | convert_to_string |
PDO_PARAM_INT | “ | convert_to_long/null | ” | convert_to_string | convert_to_string |
PDO_PARAM_BOOL | “ | convert_to_long/null | ” | convert_to_string | convert_to_string |
PDO_PARAM_NULL | “ | always null | ” | always null | if zval IS_NULL |
PDO_PARAM_LOB | “ * | convert_to_string*/null | ” | convert_to_string* | convert_to_string * |
stream support | * Supports streams | * Supports streams | * Supports streams | * Supports streams |
mysql:
firebird: Check if field allows null, for empty strings and field type is SQL_SHORT, SQL_LONG, SQL_INT64, SQL_FLOAT, SQL_DOUBLE, SQL_TIMESTAMP, SQL_TYPE_DATE, SQL_TYPE_TIME null is assumed as input
odbc: zval == IS_NULL or PDO_PARAM_NULL => always SQL_NULL_DATA
PostgreSQL: zval == IS_BOOL => always bool except if set to PDO_PARAM_NULL (Does reference check, and zval separation before convert_to_string if it isn't a reference)
PDO Binding behaviour RFC
for all bindValue/bindParam/execute input
zval/PDO | PDO_PARAM_NULL | PDO_PARAM_BOOL | PDO_PARAM_INT | PDO_PARAM_STR | PDO_PARAM_LOB | PDO_PARAM_AUTO (new) |
---|---|---|---|---|---|---|
IS_NULL | - no convert - | SQL_NULL | SQL_NULL | SQL_NULL | SQL_NULL | SQL_NULL |
IS_LONG | SQL_NULL | convert_to_boolean | - no convert - | convert_to_string | convert_to_string | zval type |
IS_DOUBLE | SQL_NULL | convert_to_boolean | - no convert - | convert_to_string | convert_to_string | zval type |
IS_BOOL | SQL_NULL | - no convert - | convert_to_long | convert_to_string | convert_to_string | zval type |
IS_ARRAY | Exception | Exception (2) | Exception (2) | Exception (2) | Exception | Exception/zval type(2) |
IS_OBJECT | Exception | Exception (1) | Exception (1) | _toString or Exception | _toString or Exception | Exception |
IS_STRING | empty => Null | Exception | convert_numeric or Exception | - no convert - | - no convert - | zval type |
IS_RESSOURCE | Exception | Exception | Exception? | convert_to_string(3) | convert_to_string(3) | convert_to_string(3) |
(1) there is no _toType yet
(2) An Array of PDO_PARAM_AUTO could be added for Databases allowing Arrays? PostgreSQL?
(3) Allowing streams
For compatibility the execute() function could be changed to PDO_PARAM_AUTO for less BC breaks.