|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54508 mysqli: truncated floats
Submitted: 2011-04-11 19:07 UTC Modified: 2011-04-13 11:53 UTC
From: anthon dot pang at gmail dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.3.6 OS: Linux
Private report: No CVE-ID: None
 [2011-04-11 19:07 UTC] anthon dot pang at gmail dot com
There's an inconsistency in behaviour between mysqli and PDO_MSYQL in the following SELECT, e.g.,

SELECT TRUNCATE(SUM(aFloatColumn),2) FROM aTable;

Let's say the sum of the column is 42.001.

With PDO_MYSQL, you'll get "42.00".

But with MYSQLI, you'll instead get "42".

Test script:
$link = mysqli_connect("localhost", "user", "password", "dbname");

$query = 'CREATE TABLE t (f FLOAT)';
$stmt = mysqli_prepare($link, $query);

$query = 'TRUNCATE TABLE t';
$stmt = mysqli_prepare($link, $query);

$query = 'INSERT INTO t (f) VALUES (42.001)';
$stmt = mysqli_prepare($link, $query);

$query = "SELECT truncate(sum(f), 2) from t";
$stmt = mysqli_prepare($link, $query);

mysqli_stmt_bind_result($stmt, $revenue);
while (mysqli_stmt_fetch($stmt)) {
    printf ("%s\n", $revenue);


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-13 11:53 UTC]
-Status: Open +Status: Bogus
 [2011-04-13 11:53 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

PDO is using emulation of prepared statements by default. By such it is executing a regular "query" command which uses the MySQL "text" protocol. When using prepared statements with mysqli it is using true prepared statements and they are using the binary protocol for talking to the MySQL server. This means data is received in different formats and by such is interpreteded differently.
 [2011-04-14 13:55 UTC] anthon dot pang at gmail dot com
Thank you very much for the explanation.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Mar 02 18:01:29 2024 UTC