|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-10-02 15:35 UTC] hejl dot tomas at gmail dot com
[2017-10-22 15:04 UTC] ab@php.net
-Status: Open
+Status: Duplicate
[2017-10-22 15:04 UTC] ab@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 21:00:01 2025 UTC |
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