3

Strange, i am using apache + php with windows. php processed mysql bit fields as number: it's work correct;

$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' '--with-gd'

i need

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

What option changing it?

-- Thanx

5
  • 2
    What does $row["bit_field"] contain? Commented Oct 17, 2010 at 11:57
  • 2
    "Strange, I am using apache + php with windows." - Indeed. :-) Commented Oct 17, 2010 at 11:57
  • 3
    @Tomalak pah. It's not 1999 anymore. Apache + Win work like a charm :) Commented Oct 17, 2010 at 12:06
  • @Pekka: I did not say it would not work. :-) Commented Oct 17, 2010 at 12:12
  • 1
    I have the exact problem, under Linux/php I have to use ord($row['bit_field']) to get a 0 or 1 value, while for windows, I can simply use $row['bit_field']. I'm using the same MySQL server. Commented Mar 15, 2011 at 10:23

1 Answer 1

5

If the field you're dealing with is indeed a bit field, then surely you should be using the bit field operators to test what 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'); }

You can use these to check individual bits in a bit field regardless of the values of the other bits.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.