Since converting to PDO for almost all the database interaction I do I've not really had any bad experiences, sure I got a few crashes here and there early on, but since then it's been pretty good.
However, there is one thing I'd really like to see.
When using prepared statements, I would love to have an extended syntax which would allow me to bind either a single value or an array and have the query modified appropriately.
For example:
$db = new PDO('live_profile');
$stmt = $db->prepare('SELECT * FROM sometable WHERE my_column = :+var');
// Execute it with a single value
// And the query becomes:
// SELECT * FROM sometable WHERE my_column = 'single_value'
$stmt->execute( array('var' => 'single_value') );
// Execute it with an array
// And the query becomes:
// SELECT * FROM sometable WHERE my_column IN('value1','value2')
$stmt->execute( array('var' => array('value1', 'value2')) );
The :+ variable expansion method would search back for the = operator before the variable, and replace it if necessary with the array method, full compatibility could be maintained just using : for variable binding and omitting the + completely.
Alternatively MySQL could allow multiple values to be used with the = operand, for example:
SELECT * FROM sometable WHERE my_column = ('value1', 'value2')
Being synonymous with:
SELECT * FROM sometable WHERE (my_column = 'value1' OR my_column = 'value2')
It would make my life much easier.
Leave a Reply