php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68657 Reading 4 byte floats with Mysqli and libmysqlclient has rounding errors
Submitted: 2014-12-26 21:55 UTC Modified: 2015-01-07 23:25 UTC
From: [email protected] Assigned: keyur (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.5.20 OS: Any
Private report: No CVE-ID: None
 [2014-12-26 21:55 UTC] [email protected]
Description:
------------
This is similar to the bug 67839.

The patch for that was only done to the mysqlnd driver and needs to be reapplied to the libmysqlclient driver as well.

Test script:
---------------
On a MySQL DB, run the following queries:

CREATE TABLE test(id INT PRIMARY KEY, fp4 FLOAT, fp8 DOUBLE) ENGINE = InnoDB;
INSERT INTO test(id, fp4, fp8) VALUES (1, 9.9999, 9.9999)

Now using mysqli, SELECT the one row out:
        $id = null;
        $fp4 = null;
        $fp8 = null;

        $stmt = mysqli_prepare($link, "SELECT * FROM test");
        mysqli_stmt_bind_result($stmt, $id, $fp4, $fp8);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_fetch($stmt);

        $test = array($id, $fp4, $fp8);

        var_dump($test);


Expected result:
----------------
It should be:
array(3) {
  [0]=>
  int(1)
  [1]=>
  float(9.9999)
  [2]=>
  float(9.9999)
}

Actual result:
--------------
The output will be:
array(3) {
  [0]=>
  int(1)
  [1]=>
  float(9.9998998642)
  [2]=>
  float(9.9999)
}

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-26 21:56 UTC] [email protected]
-Assigned To: +Assigned To: keyur
 [2015-01-07 23:25 UTC] [email protected]
-Status: Assigned +Status: Closed
 [2015-01-07 23:25 UTC] [email protected]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 31 08:00:02 2025 UTC