php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74128 mysqli_fetch_* functions return wrong format for BIT columns
Submitted: 2017-02-19 17:06 UTC Modified: 2017-10-22 15:04 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: john at coachaccountable dot com Assigned:
Status: Duplicate Package: MySQLi related
PHP Version: 7.1.2 OS: Windows 10
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: john at coachaccountable dot com
New email:
PHP Version: OS:

 

 [2017-02-19 17:06 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-02 15:35 UTC] hejl dot tomas at gmail dot com
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
 [2017-10-22 15:04 UTC] ab@php.net
-Status: Open +Status: Duplicate
 [2017-10-22 15:04 UTC] ab@php.net
See #75018. Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC