Re: [PDO] Fixing bug #44639 for mysql

[email protected] (Lukas Kahwe Smith) Wed, 28 Oct 2009 10:29:06 +0100
Newsgroups php.pdo
Message-ID <[email protected]>
On 27.10.2009, at 17:51, Oskar Eisemuth wrote:

> 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)


i agree that when explicitly passing a type, mysql should follow this  
and i would assume that we could do this as a bug fix.

as for the execute() approach, here it should ideally at least for  
variables of type integer/float implicitly use PDO::PARAM_INT/FLOAT.  
if this isnt the case today, then it might be too big of a BC break to  
do it now.

regards,
Lukas Kahwe Smith
[email protected]