Bug #66124 [Opn->Csd]: mysqli under mysqlnd loses precision when bind_param with 'i'
| From: | andrey@php.net | Date: | Thu, 21 Nov 2013 20:14:42 +0000 |
| Subject: | Bug #66124 [Opn->Csd]: mysqli under mysqlnd loses precision when bind_param with 'i' | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182881@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66124&edit=1
ID: 66124
Updated by: andrey@php.net
Reported by: sskaje at gmail dot com
Summary: mysqli under mysqlnd loses precision when bind_param
with 'i'
-Status: Open
+Status: Closed
Type: Bug
Package: MySQLi related
Operating System: CentOS/Ubuntu 64bit
PHP Version: Irrelevant
-Assigned To:
+Assigned To: andrey
Block user comment: N
Private report: N
New Comment:
Fixed in the next 5.4 version. SHould be 5.4.23
Previous Comments:
------------------------------------------------------------------------
[2013-11-20 09:05:26] sskaje at gmail dot com
Description:
------------
in ext/mysqlnd/mysqlnd_ps_codec.c:
line 572->593, 632->648
bind_param() with 'i' is processed like
1 copy to tmp_data
2 call convert_to_double_ex
but the convert_to_double_ex makes the input 64-bit-numeric string losing it's precision.
This works fine with the libmysqlclient based build.
I tried changing the two convert_to_double_ex to convert_to_long_ex, works for this issue but not
sure if it would take any side effect.
Test script:
---------------
<?php
/*
CREATE TABLE
ndtest (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
*/
$host = '172.16.3.53';
$user = 'sskaje';
$pass = 'sskaje';
$name = 'test';
$port = '3306';
$id = '1311200011005001566';
$mysqli = new mysqli($host, $user, $pass, $name, $port);
#delete data
$query = "DELETE FROM ndtest";
$mysqli->query($query);
$query = "INSERT INTO ndtest SET id=?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('i', $id);
echo "declare i\n";
$ret = $stmt->execute();
if($ret){
echo "insert id:{$id}=>{$stmt->insert_id}\n";
}else{
echo "insert failed.\n";
}
$query = "SELECT * FROM ndtest";
$result = $mysqli->query($query);
if($result){
while ($row = $result->fetch_assoc()) {
echo "fetch id:{$row['id']}\n";
}
}
echo "\n\n";
$query = "DELETE FROM ndtest";
$mysqli->query($query);
$query = "INSERT INTO ndtest SET id=?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('s', $id);
echo "declare s\n";
$ret = $stmt->execute();
if($ret){
echo "insert id:{$id}\n";
}else{
echo "insert failed.\n";
}
$query = "SELECT * FROM ndtest";
$result = $mysqli->query($query);
if($result){
while ($row = $result->fetch_assoc()) {
echo "fetch id:{$row['id']}\n";
}
}
Expected result:
----------------
[root@zhouyu php-5.5.5]# /usr/local/php/bin/php /root/ndtest.php
declare i
insert id:1311200011005001566=>1311200011005001566
fetch id:1311200011005001566
declare s
insert id:1311200011005001566
fetch id:1311200011005001566
Actual result:
--------------
[root@QA_Server81 ~]# /usr/local/php/bin/php /root/ndtest.php
declare i
insert id:1311200011005001566=>1311200011005001472
fetch id:1311200011005001472
declare s
insert id:1311200011005001566
fetch id:1311200011005001566
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66124&edit=1