Bug #66124 [NEW]: mysqli under mysqlnd loses precision when bind_param with 'i'

From: Date: Wed, 20 Nov 2013 09:05:27 +0000
Subject: Bug #66124 [NEW]: mysqli under mysqlnd loses precision when bind_param with 'i'
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182850@lists.php.net to get a copy of this message
From:             sskaje at gmail dot com
Operating system: CentOS/Ubuntu 64bit
PHP version:      Irrelevant
Package:          MySQLi related
Bug Type:         Bug
Bug description:mysqli under mysqlnd loses precision when bind_param with 'i'

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 bug report at https://bugs.php.net/bug.php?id=66124&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=66124&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=66124&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=66124&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=66124&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=66124&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=66124&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=66124&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=66124&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=66124&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=66124&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=66124&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=66124&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=66124&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66124&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=66124&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=66124&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=66124&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66124&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=66124&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=66124&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#182850) next »