|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2007-11-06 09:22 UTC] lafriks at inbox dot lv
 Description: ------------ 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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 21:00:02 2025 UTC | 
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"'); $stmt->execute(); $rs = $stmt->fetch(); $stmt->closeCursor(); 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); $stmt->execute(); $rs = $stmt->fetch(); $stmt->closeCursor(); 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); $stmt->execute(); $rs = $stmt->fetch(); $stmt->closeCursor(); 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); $stmt->execute(); $rs = $stmt->fetch(); $stmt->closeCursor(); 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.