From: oliver dot graetz at gmx dot de Operating system: Linux/Debian/Dotdeb PHP version: 5.2.3 PHP Bug Type: PDO related Bug description: float parameters truncated to integer in prepared statements
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 ) ) -- Edit bug report at http://bugs.php.net/?id=41698&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41698&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41698&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41698&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41698&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41698&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41698&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41698&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41698&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41698&r=support Expected behavior: http://bugs.php.net/fix.php?id=41698&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41698&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41698&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41698&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41698&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41698&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41698&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41698&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41698&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41698&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41698&r=mysqlcfg