|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43203 PDO better support for float bind values
Submitted: 2007-11-06 09:22 UTC Modified: 2011-02-21 20:54 UTC
Avg. Score:4.6 ± 0.7
Reproduced:37 of 37 (100.0%)
Same Version:7 (18.9%)
Same OS:7 (18.9%)
From: lafriks at inbox dot lv Assigned:
Status: Open Package: PDO related
PHP Version: 5.2.4 OS:
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: lafriks at inbox dot lv
New email:
PHP Version: OS:


 [2007-11-06 09:22 UTC] lafriks at inbox dot lv
It would be way easier to work with PDO if there was PDO::PARAM_FLOAT. Otherwise there is always need to check for comma and point if in different locales and that just makes it unnecessary hard to work with float numbers and binding to prepared statements.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-21 20:54 UTC]
-Package: Feature/Change Request +Package: PDO related
 [2012-01-20 10:31 UTC] r dot wilczek at web-appz dot de
The missing PDO::PARAM_DOUBLE actually leads to very annoying problems.

SQLite considers a NUMERIC to be always less than a TEXT or REAL.
So string '1' is not less than double 1.1.

The following unparameterized statement shows this behaviour:
$rs = $sqlite->prepare('SELECT '1' < 1.1 as "result"');
$rs = $stmt->fetch();
print_r($rs['result']); // 0 works as expected (and the same way as SQLite CLI.)

Now we try to perform the same operation using a parameterized statement:
$stmt = $sqlite->prepare('SELECT :left < :right as "result"');

Option A. Binding double as string:
$stmt->bindValue(':left', '1', PDO::PARAM_STR); 
$stmt->bindValue(':right', 1.1, PDO::PARAM_STR); 
$rs = $stmt->fetch();
print_r($rs['result']); // 1 failure.  

Option B. Binding double as integer:
$stmt->bindValue(':left', '1', PDO::PARAM_STR); 
$stmt->bindValue(':right', 1.1, PDO::PARAM_INT);
$rs = $stmt->fetch();
print_r($rs['result']); // 0 Seems to work, but ...

... this way we cannot tell double from integer. SQLite would consider
integer 1 to be less than double 1.1. 
$stmt->bindValue(':left', 1, PDO::PARAM_INT); 
$stmt->bindValue(':right', 1.1, PDO::PARAM_INT);
$rs = $stmt->fetch();
print_r($rs['result']); // 0 Failure

So there is no way with PDO to correctly parameterize double values. 
I request to provide PDO::PARAM_DOUBLE.
 [2015-10-20 16:34 UTC] et at traede dot com
+1, this is a really annoying issue, and the only way to circumvent it is to walk manually through every result set and cast to float every value. I can't believe there has been no activity on this for almost 4 years
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 06:01:27 2024 UTC