#48855 [Opn->Ver]: Decimals are rounded with PDO bindValue in mysql double/float fields

From: Date: Tue, 22 Sep 2009 16:51:45 +0000
Subject: #48855 [Opn->Ver]: Decimals are rounded with PDO bindValue in mysql double/float fields
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-142694@lists.php.net to get a copy of this message
ID: 48855 Updated by: uw@php.net Reported By: lorenzo-99 at libero dot it -Status: Open +Status: Verified Bug Type: PDO related Operating System: Windows XP PHP Version: 5.2.10 New Comment: That is a PDO bug not a PDO_MYSQL bug. It has been fixed in PHP 5.3+. ext/pdo/pdo_stmt.c:330 needs something like this: int len = spprintf(&p, 0, "%.*H", (int) EG(precision), Z_DVAL_P(param->parameter)); I don't know what the policy is with PHP 5.2. Would be nice if someone else could apply the patch. I am quite sure to have seen this bug before and I am also sure the 5.3 tests cover it. Though, I can't say which test from top of my head. Previous Comments: ------------------------------------------------------------------------ [2009-07-08 16:48:03] lorenzo-99 at libero dot it Description: ------------ I'm inserting a new record in a Mysql table with a PDO routine, the table have a double field (not specified the scale and size for the field), I'm using the bindValue function, I try to save the value 9.1234567 in the field, after the insert I found it saves 9.123457, so maximum 6 decimals (with rounding). The same problem happens with a float field, in this case it saves maximum 5 decimals I didn't try with other dbms, my Mysql version is 5.1.36 (i verified that the problem happens also with older versions) Reproduce code: --------------- This saves only 6 decimal (using bindValue): $sth = $dbh->prepare("INSERT INTO intrapportal.regioni ( idRegione ,descrRegione , provadouble ) VALUES ('xxxx', 'yyyyy', :value)"); /*** bind values ***/ $sth->bindValue(':value', 9.1234567, PDO::PARAM_STR); /*** execute the prepared statement ***/ $sth->execute(); This saves all decimals (without bindValue) $sth = $dbh->prepare("INSERT INTO intrapportal.regioni ( idRegione ,descrRegione , provadouble ) VALUES ('xxxx', 'yyyyy', 9.1234567)"); /*** execute the prepared statement ***/ $sth->execute(); ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48855&edit=1

« previous php.bugs (#142694) next »