What are losses with binding all PDO params as PARAM_STR?
I'm creating a simple query builder for PHP PDO, to create queries faster, without doing lot of bind's and split query creating process to parts where conditions/orders/limits are composed together in dependency on some conditions (like filter engine, where you can select some criteria). I have meth开发者_如何学运维od like this:
$query->addWhere( 'uid', '>' , 100 );
Which adds where condition and binds :uid to 100, i can also omitt bindig like this:
$query->addWhere( 'date', '>' , 'NOW()' , false );
But i don't bring information of 100 parameter type. Deeper in executing query, i don't do bindParam or bindValue, but passing my binded table to execute:
$stmt->execute( $query->getBinds() );
Do all of my parameters are treated as PARAM_STR or it gets PDO type from variable type in array ? What can I lose with that ? only performance/memory or there is possible some loss of data or logical error ?
P.S. I don't want to create another classes for params, because I want keep it simple, I mean something like:
$query->addWhere( new Field('uid') , '=' , new IntParam( 100 ) ); or something
Although I see nothing good in such query builders (You gain as little as omitting few words and lose as many as making totally unreadable code out from precious SQL), the answer no: no loss.
Just turn emulating mode off, and PDO will detect necessary types automatically.
$dbh->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
精彩评论