php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48855 Decimals are rounded with PDO bindValue in mysql double/float fields
Submitted: 2009-07-08 16:48 UTC Modified: 2009-09-25 15:06 UTC
From: lorenzo-99 at libero dot it Assigned:
Status: Closed Package: PDO related
PHP Version: 5.2.10 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lorenzo-99 at libero dot it
New email:
PHP Version: OS:

 

 [2009-07-08 16:48 UTC] 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();


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-22 16:51 UTC] uw@php.net
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. 
 [2009-09-23 10:32 UTC] uw@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php

Hmm, seems to have been fixed before in SVN and in PHP 5.2.11:

        if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_STR && param->max_value_len <= 0 && ! ZVAL_IS_NULL(param->parameter)) {
                if (Z_TYPE_P(param->parameter) == IS_DOUBLE) {
                        char *p;
                        int len = spprintf(&p, 0, "%.*H", (int) EG(precision), Z_DVAL_P(param->parameter));
                        ZVAL_STRINGL(param->parameter, p, len, 0);
                } else {
                        convert_to_string(param->parameter);
                }

 [2009-09-25 13:58 UTC] lorenzo-99 at libero dot it
Sorry but The Problem in 5.3 is NOT fixed.

I tried first to install 5.2.11 and i verified that the problem is fixed, then I update to 5.3 but the problem here still exists

I download the windows version from http://windows.php.net/download/

php-5.3.0-Win32-VC6-x86.zip thread-safe

The strange thing I see is that 5.3 is dated 2009-jun-30 while 5.2.11 is more recent 2009-sep-17
 [2009-09-25 14:13 UTC] uw@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-09-25 15:06 UTC] lorenzo-99 at libero dot it
Ok in this last version (5.3.2dev) the problem is really fixed.
So I consider the problem closed
thank you very much
 [2010-05-14 10:00 UTC] r dot wilczek at web-appz dot de
This bug persists in current PHP 5.3.2 with MySQL 5.1.36 and MySQL client API version 5.0.67 (64 bit Linux)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 26 08:01:30 2024 UTC