rfc:driver-specific-pdo-param-types

PHP RFC: Driver-Specific PDO Param Types

Introduction

Databases used with PDO can have nuances that fall outside the types defined by PDO (the PDO::PARAM_* consts). These nuances can't always be made transparent to the developer. A wider range of types would allow developers to create better queries. Much like PDO supports driver-specific attributes, it should also support driver-specific param types.

This issue is particularly exposed to pdo_dblib users. Since pdo_dblib relies on prepared statement emulation – DB-Library doesn't support prepared statements – developers must build queries as they should be executed by the server. There have been a couple issues logged related to this. The current workaround is to use CAST (or implicit casts) with the existing data types. Doing so adds cost to queries.

Proposal

By adding a placeholder value to enum pdo_param_type, PDO drivers can add types as they see fit. The PR contains two examples of how this would be used with pdo_dblib.

Backward Incompatible Changes

No modifications are needed to the supported PDO drivers, but they would have to be rebuilt against this API change. Other drivers might have to be modified if they make assumptions about the structure of enum pdo_param_type.

Proposed PHP Version(s)

Next PHP 7.x.

New Constants

The example code introduces the following constants:

  • PDO::DBLIB_ATTR_UNICODE_STRINGS
  • PDO::DBLIB_PARAM_BINARY
  • PDO::DBLIB_PARAM_STR_UNICODE
  • PDO::DBLIB_PARAM_STR_ASCII

Proposed Voting Choices

This project requires a 50%+1 majority.

Patches and Tests

Working implementation, with tests: https://github.com/php/php-src/pull/2168

rfc/driver-specific-pdo-param-types.txt · Last modified: 2017/09/22 13:28 (external edit)