php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38590 PDO Mysql returns garbage value for float column
Submitted: 2006-08-25 08:33 UTC Modified: 2006-08-25 10:18 UTC
From: mark-phpbugs at vectrex dot org dot uk Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.1.5 OS: Linux
Private report: No CVE-ID: None
 [2006-08-25 08:33 UTC] mark-phpbugs at vectrex dot org dot uk
Description:
------------
When selecting from a FLOAT column, PDO returns garbage instead of the right value.

Tested in PHP 5.1.2 and 5.1.6; both fail in similar ways.

Reproduce code:
---------------
<?php
	error_reporting(E_ALL);
	
	$db = new PDO("mysql:host=localhost;dbname=test", 'root', '', array());
	$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
	
	$db->exec("CREATE TEMPORARY TABLE test ( num FLOAT NOT NULL)");
	$db->exec("INSERT INTO test VALUES (1.5)");
	$st = $db->query("SELECT * FROM test");
	$row = $st->fetch(PDO::FETCH_ASSOC);
	var_dump($row);
	
?>

Expected result:
----------------
array(1) {
  ["num"]=>
  string(12) "1.5"
}


Actual result:
--------------
array(1) {
  ["num"]=>
  string(12) "-2.87989e-05"
}

Also other incorrect values; it seems nondeterministic.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-25 08:37 UTC] mark-phpbug at vectrex dot org dot uk
Using MySQL 5.0.20 and 
PDO Driver for MySQL, client library version	5.0.22
 [2006-08-25 08:47 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

Can't reproduce both with 5.2 and 5.1.5.
 [2006-08-25 10:02 UTC] mark-phpbugs at vectrex dot org dot uk
I think this is caused by the MySQL client library and server being (somewhat) incompatible versions.

I've upgraded the MySQL client and server to 5.0.24 and the problem has gone away.
 [2006-08-25 10:18 UTC] tony2001@php.net
Not PHP problem -> bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 08:01:29 2024 UTC