Bug #74128 [Com]: mysqli_fetch_* functions return wrong format for BIT columns
| From: | hejl dot tomas at gmail dot com | Date: | Mon, 02 Oct 2017 15:35:18 +0000 |
| Subject: | Bug #74128 [Com]: mysqli_fetch_* functions return wrong format for BIT columns | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211490@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74128&edit=1
ID: 74128
Comment by: hejl dot tomas at gmail dot com
Reported by: john at coachaccountable dot com
Summary: mysqli_fetch_* functions return wrong format for BIT
columns
Status: Open
Type: Bug
Package: MySQLi related
Operating System: Windows 10
PHP Version: 7.1.2
Block user comment: N
Private report: N
New Comment:
Reproduced on up-to-date Windows 10, with this build:
PHP Version 7.1.8
System Windows NT PC-2016 10.0 build 15063 (Windows 10) i586
Build Date Aug 1 2017 20:56:01
Compiler MSVC14 (Visual C++ 2015)
Architecture x86
Previous Comments:
------------------------------------------------------------------------
[2017-02-19 17:06:45] john at coachaccountable dot com
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 this bug report at https://bugs.php.net/bug.php?id=74128&edit=1