Php mysql bit fields

Strange, I use apache + php with windows. php processed fields mysql bits as number: it works correctly;

$b = $row['bit_field'] 
if ($b == 1) {
  echo 'ok';
}

with centos and php 5.3.3 './configure' '--with-mysql' '--with-mcrypt' '--enable-mbstring' '--with-imap' '--with-kerberos'' - with-imap-ssl '' --with-libjpeg '' --with-libpng '' --wd-gd '

I need

$b = $row['bit_field'] 
if (ord($b) == 1) {
  echo 'ok';
}

Which option to change it?

- Thanx

+3
source share
1 answer

If the field you are dealing with is really a bit field, then of course you should use bit field operators to check which bits are set in the value?

if ($b & 0X1) { echo ('Least significant bit in byte set'); }
if ($b & 0X80) { echo ('Most significant bit in byte set'); }
if ($b & 0X80000000) { echo ('Most significant bit in 32 bit word set'); }

.

+4

Source: https://habr.com/ru/post/1769969/


All Articles