Hi Adam,

 

From: Adam Baratz [mailto:adambar...@php.net] 
Sent: Friday, May 19, 2017 1:26 PM



Maybe even a better way is just to change default param type from PARAM_STR to 
PARAM_AUTO in bindValue family routines, without any driver options or configs.
So if drivers supports server prepares with type hinting, OK: treat it better, 
if not, push it as a string like is now.

 

I'm not sure that changes the proposal too much. My position is still that I'd 
like PDO to be less "magical," to put more of the burden on providing the right 
content to the user. 

 

 

 

 

 

 

 

Much of PHP internals are about providing a light layer on a third-party 
library (in this case, all the DB libraries). You can then compose them as 
needed to get the right functionality for your application. We get a lot of 
power and flexibility from that. Making APIs that are too "opinionated" makes 
it harder for users to control their destiny.

 

I haven't tested this, but I think you could implement the functionality you 
need in userland. You could write a class like this:

 

class MyPDOStatement extends \PDOStatement {

  public function bindValue($parameter, $value, $data_type = -1) { // or define 
a const somewhere for an AUTO type

    if ($data_type == -1) {

      switch (gettype($value) {

        case 'boolean':

          $data_type = \PDO::PARAM_BOOL;

          break;

        default:

          $data_type = \PDO::PARAM_STR;

          break;

 

Reply via email to