pdo bindParam() with named parameters
| From: | Lukas Smith | Date: | Thu, 10 Feb 2005 10:02:09 +0000 |
| Subject: | pdo bindParam() with named parameters | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-1947@lists.php.net to get a copy of this message | ||
Hi,
I just wanted to put in a more formal request to reconsider the requirement to prefix named parameters with a colon.
As in
$stmt->bindParam(':foo', $bar);
Here are Wez's reasons for things being the way they are:
* "1" smells like 1, which means bind by position. This can cause ambiguity if you decide to bind some parameters by name and others by position (and you hav e decided to name your parameters after numbers).
* For drivers that natively support named parameters (sqlite and OCI), those keys are passed directly to the driver
* Some drivers (MS-SQL and ODBC/DB-2) will support parameters that have an @ prefix instead of a colon when invoking stored procedures. If PDO assumed that ":" was always the prefix, things would get very ugly in the code very quickly
* and lastly, performance. Why should we force PDO to have to allocate a new copy of the string with the prefix when the programmer can supply it as it is supposed to be sent?
The reality will be that in most cases users will not care about the first 3 points. The performance impact will therefore likely be slightly against the current solution as now the colon needs to be appended in PHP userland.
Therefore I propose to handle the original need for the colon through a 3rd optional parameter that users can set if they want to get the above mentioned additional functionality, while keeping things simple and fast for the vast majority of users.
regards,
Lukas