Fixing bug #44639 for mysql

[email protected] (Oskar Eisemuth) Tue, 27 Oct 2009 17:51:11 +0100
Newsgroups php.pdo
Message-ID <[email protected]>
Hello

If a user does bindValue(':limit', $someval, PDO::PARAM_INT), there is a 
problem with the mysql driver. (Bug #44639)
$someval should be (converted to) integer with PARAM_INT, but when the 
driver creates the query it does quoting instead when it's a string.

mysql_statment.c shows:
<snip>
pdo_mysql_stmt_param_hook
....
/* Is it really correct to check the zval's type? - But well, that's 
what the old code below does, too */
</snip>

This means currently PDO mysql always tries to guess what type type the 
value is even when there is a explicit type set by the user.
Maybe the plan was to allow execute(array()) to work with various types?

I do think pdo mysql need to always convert the type to the "Explicit 
data type" and then do quoting when necessary.

So a fix for the bug would change:

bindValue without type always defaults to string, (as the documentation 
tells us)
bindValue with type set always convert to the type. *new behavior for mysql*

bindParam should do the same.

The old broken way could be described as PDO::PARAM_(ZVAL)AUTO and maybe 
added as new option? (not my favorite)

Best regards
Oskar Eisemuth