Bug #74128 [NEW]: mysqli_fetch_* functions return wrong format for BIT columns
| From: | john at coachaccountable dot com | Date: | Sun, 19 Feb 2017 17:06:50 +0000 |
| Subject: | Bug #74128 [NEW]: mysqli_fetch_* functions return wrong format for BIT columns | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-207444@lists.php.net to get a copy of this message | ||
From: john at coachaccountable dot com
Operating system: Windows 10
PHP version: 7.1.2
Package: MySQLi related
Bug Type: Bug
Bug description:mysqli_fetch_* functions return wrong format for BIT columns
Description:
------------
On a 64-bit machine I've got PHP 7 installed as a Win32 application
(Windows download VC14 x86 Thread Safe (2017-Feb-14 23:28:41)).
Selecting a MySQL BIT column value via mysqli_fetch_array gives values
that are 18-digit numeric strings, as opposed to the expected 1-digit
strings ("0" or "1").
These 18 digit strings turn out to be base-10 representations of 64-bit
binary sequences. When converted, the lower end 32 bits are kinda what
we'd expect, 31 zeros and the actual value of the BIT column (as stored
in the database) in the last digit, a 0 or 1. The higher end digits are
non-deterministic, presumably the adjacent 32 bits in memory.
The actual result shows what I get when running PHP7 and using its
associated php_mysqli.dll (again, unpacking what PHP gets for the bit
value into binary is most revealing!). The expected results are what I
get when running the same code in PHP 5.6 and its associated
php_mysqli.dll.
Here are my phpInfo specifics, in case useful:
PHP Version 7.1.2
System Windows NT 6.2 build 9200 (Windows 8 Home Premium Edition) i586
Compiler MSVC14 (Visual C++ 2015)
Architecture x86
MysqlI Support enabled
Client API library version mysqlnd 5.0.12-dev - 20150407 - $Id:
b396954eeb2d1d9ed7902b8bae237b287f21ad9e $
Test script:
---------------
$DB_connection = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD,
DB_NAME); // a valid 5.x MySQL database
mysqli_query($DB_connection, "CREATE TABLE IF NOT EXISTS
tblTestBits(bitValue BIT NOT NULL)");
mysqli_query($DB_connection, "INSERT INTO test_me VALUES (1), (0), (1),
(0)");
$xRS = mysqli_query($DB_connection, "SELECT bitValue FROM
tblTestBits");
while($xR = mysqli_fetch_array($xRS)) {
var_dump($xR['bitValue']); echo " ... In binary: " .
LargeIntStringToBits($xR['bitValue']) . "<br />";
};
function LargeIntStringToBits($Input) {
$Output = '';
while($Input != '0') {
$Output .= chr(48 + ($Input{strlen($Input)-1} % 2));
$Input = BCDiv($Input,'2');
}
$Output = strrev($Output);
return (($Output != '') ? $Output : '0');
};
Expected result:
----------------
string(1) "1" ... In binary: 1
string(1) "0" ... In binary: 0
string(1) "1" ... In binary: 1
string(1) "0" ... In binary: 0
Actual result:
--------------
string(18) "533409529136676865" ... In binary:
11101100111000011010010010000000000000000000000000000000001
string(18) "533409597856153600" ... In binary:
11101100111000011010011010000000000000000000000000000000000
string(18) "533409666575630337" ... In binary:
11101100111000011010100010000000000000000000000000000000001
string(18) "533409735295107072" ... In binary:
11101100111000011010101010000000000000000000000000000000000
--
Edit bug report at https://bugs.php.net/bug.php?id=74128&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74128&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74128&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74128&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74128&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74128&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74128&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74128&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74128&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74128&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74128&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74128&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74128&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74128&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74128&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74128&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74128&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74128&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74128&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74128&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74128&r=mysqlcfg