This is an old revision of the document!
PHP RFC: Extended String Types For PDO
- Version: 0.1
- Date: 2017-02-16
- Author: Adam Baratz adambaratz@php.net
- Status: Under Discussion
- First Published at: https://wiki.php.net/rfc/extended-string-types-for-pdo
Introduction
MySQL and Microsoft SQL Server define special column types for storing Unicode strings. There is a different format for literals of this type.
When using emulated prepared statements -- the default behavior for pdo_mysql, the only one for pdo_dblib -- it's not possible to quote parameters using this format. By not doing this, queries become more expensive because of an implicit cast.
There aren't many pdo_dblib users who comment regularly on the internals list, but the presence of a feature request and a pull request suggests that this is an impactful omission.
Proposal
Three constants would be added to the pdo extension:
- PDO::PARAM_STR_UNICODE. A new type, to be applied as a bitwise-OR to
PDO::PARAM_STR
. It would indicate that the value should be quoted with the N-prefix. - PDO::ATTR_UNICODE_STRINGS. This bool driver attribute would indicate whether all
PDO::PARAM_STR
values should be treated likePDO::PARAM_STR | PDO::PARAM_STR_UNICODE
by default. - PDO::PARAM_STR_ASCII. A new type, to be applied as a bitwise-OR to
PDO::PARAM_STR
. It would indicate that the value should be quoted without the N-prefix. This would be intended to be used as an exception for when thePDO::ATTR_UNICODE_STRINGS
attribute is set to true.
Backward Incompatible Changes
Since this functionality would be opt-in, existing code would continue to work as it does. The bitmasked values would be ignored by other drivers, or pdo_mysql toggling off prepared statement emulation, so the portability valued for PDO code would be preserved.
Impact To Existing Extensions
Drivers outside of php-src might have to be modified if they make assumptions about the structure of enum pdo_param_type
. They would have to be rebuilt since the PDO_DRIVER_API
macro would be updated.
Proposed PHP Version(s)
Next PHP 7.x.
Proposed Voting Choices
This project requires a 50%+1 majority.