1

I'm not sure if it's PHP or MySQL that's messing me up.

Say, I have a table with BIGINT UNSIGNED column (let's name it flgs). I read data from that table with PHP as such:

$query = "SELECT * FROM `$tbl_nm` ORDER BY `$colID` ASC";

$res = mysqli_query($link, $query);
if($res)
{
    while($aRow = mysqli_fetch_assoc($res))
    {
        echo("flags=0x".dechex($aRow['flgs'])."<br>");
    }
}

if the flgs column has value with bit-63 reset, then I get the correct result. But if bit-63 is set, the return value is 0x7fffffffffffffff. Hmmmm?

For instance, if flgs is set to 0x8000000000000000 in the database, my code above prints:

flags=0x7fffffffffffffff

Why, PHP, why?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • @Shadow: how is it a duplicate? This is not about displaying a column as a hex. Did you even try to understand it? – c00000fd Mar 01 '20 at 09:23
  • Sorry to point out, but your question, as it is written, is about displaying a column in hex. If that's not what you are after, then you should have made that clear. But added another duplicate on handling unsigned bigints in php. – Shadow Mar 01 '20 at 09:39

0 Answers0