Edit report at http://bugs.php.net/bug.php?id=54508&edit=1

 ID:                 54508
 Comment by:         anthon dot pang at gmail dot com
 Reported by:        anthon dot pang at gmail dot com
 Summary:            mysqli: truncated floats
 Status:             Bogus
 Type:               Bug
 Package:            MySQLi related
 Operating System:   Linux
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

Thank you very much for the explanation.


Previous Comments:
------------------------------------------------------------------------
[2011-04-13 11:53:11] johan...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

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-11 19:07:59] anthon dot pang at gmail dot com

Description:
------------
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:
---------------
<?php

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



$query = 'CREATE TABLE t (f FLOAT)';

$stmt = mysqli_prepare($link, $query);

mysqli_stmt_execute($stmt);



$query = 'TRUNCATE TABLE t';

$stmt = mysqli_prepare($link, $query);

mysqli_stmt_execute($stmt);



$query = 'INSERT INTO t (f) VALUES (42.001)';

$stmt = mysqli_prepare($link, $query);

mysqli_stmt_execute($stmt);



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

$stmt = mysqli_prepare($link, $query);

mysqli_stmt_execute($stmt);



mysqli_stmt_bind_result($stmt, $revenue);

while (mysqli_stmt_fetch($stmt)) {

    printf ("%s\n", $revenue);

}



mysqli_stmt_close($stmt);

mysqli_close($link);



Expected result:
----------------
42.00

Actual result:
--------------
42


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54508&edit=1

Reply via email to