|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-01-13 22:02 UTC] erik at ekriirke dot com
[2009-01-13 22:22 UTC] erik at ekriirke dot com
[2009-08-26 12:45 UTC] andrey@php.net
[2009-08-26 17:04 UTC] erik at ekriirke dot com
[2009-10-08 14:52 UTC] jani@php.net
[2009-10-09 17:35 UTC] erik at ekriirke dot com
[2009-10-16 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 07:00:01 2025 UTC |
Description: ------------ This happens the same on Linux (RHE5) and Windows (Server2K,XPPro) Differing versions of MySQL as well (5.0.51a, 5.1.11) Using either MySQLi or MySQL extensions I have a table with an UNSIGNED INTEGER column. The value in the column has a value where MSB (31) is set (0x80000000 and higher). Selecting this value into an array via either mysql_fetch_assoc, mysql_fetch_row (and mysqli variant) stores the value correctly as displayed by either a print_r or echo'ing directly. Should I perform a math operation (+-*/) the result is correct. Should I perform a bitwise operation or function the answers are wrong. It appears doing so internally changes the selected value to 0x7FFFFFFF no matter its original value as long as bit 31 is set. However, if I perform math on the value THEN a bitwise operation, the result is correct. Now, I know the MSB is a touchy subject in 31bit math, but there is inconsistency here. Reproduce code: --------------- $q=mysql_query("SELECT val FROM test"); // val is an UNSIGED INT containing a value with MSB set. Ex: 2147488308 (0x80001234) $a=mysql_fetch_assoc($q); echo $a['val'],"<br>\n"; //2147488308 - correct echo dechex($a['val']),"<br>\n"; //7fffffff - wrong echo $a['val']+0,"<br>\n"; //2147488308 - correct echo $a['val']+1,"<br>\n"; //2147488309 - correct echo $a['val']|0,"<br>\n"; //2147483647 - wrong echo dechex($a['val']+0),"<br>\n"; //80001234 - correct echo $a['val']&1,"<br>\n"; //1 - wrong echo ($a['val']+0)&1,"<br>\n"; //0 - correct /*** Workaround ***/ $a['val']+=0; //as long as some kind of math was performed it functions correctly afterward echo $a['val']|0,"<br>\n"; //2147488308 or -2147478988 - correct echo $a['val']&1,"<br>\n"; //0 - correct echo dechex($a['val']),"<br>\n"; //80001234 - correct Expected result: ---------------- 2147488308 80001234 2147488308 2147488309 -2147478988 80001234 0 0 -2147478988 0 80001234 Actual result: -------------- 2147488308 7fffffff 2147488308 2147488309 2147483647 80001234 1 0 -2147478988 0 80001234