php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41698 float parameters truncated to integer in prepared statements
Submitted: 2007-06-15 09:16 UTC Modified: 2007-06-26 01:24 UTC
Votes:5
Avg. Score:4.6 ± 0.5
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: oliver dot graetz at gmx dot de Assigned: iliaa (profile)
Status: Closed Package: PDO related
PHP Version: 5.2.3 OS: Linux/Debian/Dotdeb
Private report: No CVE-ID: None
 [2007-06-15 09:16 UTC] oliver dot graetz at gmx dot de
Description:
------------
This is yet another locale issue...

When setting the locale to a value where "," is used as decimal point, then float parameters are truncated to integers. My example does not use a string for the parameter, it reaches the execute() as float value! This means that in userland there are no other workarounds than resetting the locale settings for the statement execution or hand-crafting a "stringified" float value of "4.56".

Since PDO does not offer a PDO::PARAM_FLOAT constant (at least it is not stated in the documentation) I assume that the PDO code treats the values as string. Since the DBMS side of the PDO operation does NOT adhere to PHP locale settings this is a serious design flaw. Statement parameters of type float should be converted to string with "." as decimal point regardless of the locale setting on the PHP side.

Reproduce code:
---------------
$pdo->exec('CREATE TABLE test(floatval DECIMAL(8,6))');
$pdo->exec('INSERT INTO test VALUES(2.34)');
$value=4.56;
$stmt=$pdo->prepare('INSERT INTO test VALUES(?)');
$stmt->execute(array($value));


Expected result:
----------------
Array
(
    [0] => Array
        (
            [floatval] => 2.340000
            [0] => 2.340000
        )

    [1] => Array
        (
            [floatval] => 4.560000
            [0] => 4.560000
        )

)


Actual result:
--------------
Array
(
    [0] => Array
        (
            [floatval] => 2.340000
            [0] => 2.340000
        )

    [1] => Array
        (
            [floatval] => 4.000000
            [0] => 4.000000
        )

)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-17 14:01 UTC] iliaa@php.net
What database driver are you using?
 [2007-06-17 14:33 UTC] oliver dot graetz at gmx dot de
The PDO driver is pdo_mysql, client library version 4.1.15.
The DBMS is MySQL 5.0.41.
The system is Debian Sarge with Dotdeb packages.
 [2007-06-26 01:24 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC