|  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
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: oliver dot graetz at gmx dot de
New email:
PHP Version: OS:


 [2007-06-15 09:16 UTC] oliver dot graetz at gmx dot de
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)');
$stmt=$pdo->prepare('INSERT INTO test VALUES(?)');

Expected result:
    [0] => Array
            [floatval] => 2.340000
            [0] => 2.340000

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


Actual result:
    [0] => Array
            [floatval] => 2.340000
            [0] => 2.340000

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



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-17 14:01 UTC]
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]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Mar 02 23:01:32 2024 UTC