|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34681 MySQL double type loses trailing zeroes with mysqli prepared statements
Submitted: 2005-09-29 17:09 UTC Modified: 2005-10-03 15:36 UTC
From: adrian at fuzzee dot co dot uk Assigned: georg (profile)
Status: Not a bug Package: MySQLi related
PHP Version: 5CVS-2005-09-29 (cvs) OS: *
Private report: No CVE-ID: None
 [2005-09-29 17:09 UTC] adrian at fuzzee dot co dot uk
With mysqli statements, a MySQL double loses trailing zeroes, so '0.000' becomes just '0' and '3.350' would become '3.35'. However, if you use regular mysqli queries (non prepared statements) the trailing zeroes are preserved... Obviously not a fatal bug, but an odd difference in behaviour.

Reproduce code:
	$sql = "SELECT 0.000 as number";
	$mysqli = new mysqli(...);
	$stmt = $mysqli->prepare($sql);
	echo "$number\n";

	$r = $mysqli->query($sql);
	$tmp = $r->fetch_array();
	echo "$tmp[0]\n";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-29 17:54 UTC]
By replacing the echo's with var_dump() calls, I get this:

array(2) {
  string(5) "0.000"
  string(5) "0.000"

So what you think is truncation is simply how PHP handles floats. Try "echo 0.00;" for example.

Assigned to Georg since this seems really inconsistent behaviour first. (perhaps just needs to be documented?)

 [2005-09-30 10:29 UTC]
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.

What MySQL Version do you use, which client library version?
 [2005-09-30 11:11 UTC]
I tested with these (mysql --version):

mysql  Ver 14.7 Distrib 4.1.13, for pc-linux-gnu (i686) using readline 4.3
mysql  Ver 14.7 Distrib 4.1.12, for pc-linux-gnu (i686) using readline 4.3

I don't know what you meant with 'client library version'.

 [2005-10-03 15:36 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

If you want to convert double value to a string, use MySQL 
cast function: SELECT CAST(1.234 AS CHAR) FROM DUAL 
While mysql_query uses a string based protocol (server 
sends all values as string), prepared statements use 
binary protocol, which was introduced in MySQL 4.1. That 
means numeric values will be transferred in binary 
representation and stored in PHP's corresponding data 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 10:01:29 2024 UTC