The “national character” type was introduced in SQL-92 (section 4.2.1). It's an open-ended type. The spec indicates that its meaning is defined by the implementation. MySQL and Microsoft SQL Server use it to store Unicode data.
There is a different format for literals of this type. Instead of simply surrounding strings with quotes, an N is added as a prefix (e.g., N'string' instead of 'string'). 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. This means that queries involving these columns will trigger implicit casts, which makes them more expensive. This issue affects MySQL and MSSQL.
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.
Three constants would be added to the pdo extension:
PDO::PARAM_STR
. It would indicate that the value should be quoted with the N-prefix.PDO::PARAM_STR
. It would indicate that the value should be quoted without the N-prefix. This would be used as an exception for when the PDO::ATTR_DEFAULT_STR_PARAM
attribute is set to PDO::PARAM_STR_NATL
.PDO::PARAM_STR
by default.
The parameter constants are more like PDO::PARAM_INPUT_OUTPUT
than PDO::PARAM_STR
. They're flags to be applied to other parameters. This would also mean that code portability would be preserved. Drivers that don't need the hints for true prepared statements would ignore them.
Example:
$db->quote('über', PDO::PARAM_STR | PDO::PARAM_STR_NATL); // N'über' $db->quote('A'); // 'A' $db->setAttribute(PDO::ATTR_DEFAULT_STR_PARAM, PDO::PARAM_STR_NATL); $db->quote('über'); // N'über' $db->quote('A', PDO::PARAM_STR | PDO::PARAM_STR_CHAR); // 'A'
This functionality would be strictly additive. Existing code would continue to work as it does. These constants wouldn't affect anything related to the character set used for connections.
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.
Next PHP 7.x.
Voting opened on 8 March 2017. It will close on the 17th at 0:00 UTC. This project requires a 50%+1 majority.
This feature was implemented in PHP 7.2 (4afce8ec8c6660ebd9f9eb174d2614361d1c6129).