tags:

views:

31

answers:

1

I am storing x and y as bits in mysql database, upon fetch the record using php fetch_assoc, the display is gobbled. And I can't find a way to test the value to see if it's true or false... I tried using if($val), if($val==true) if($val===true), if $val is false, all 3 tests still returns true. any idea? [x] => � [y] =>

thanks for the answer below, I now use:

function mysql_bit($bit) {

    if(ord($bit) == 0 || ord($bit) == 48)return false;
    return true;
}
 

to handle both mysql bit value and regular string/int value(from http request for example).

+1  A: 

Does this post help?

I had this issue a looooong time ago... it is read as an ascii '1' or '0'. I don't think my solution at the time was exactly as nice, but I don't have the source anymore so I will pretend it was!

function mysql_bit($bit) {
    return ord($bit) == 1 || $bit == 1;
}
Andrew Backer
You are a ****** GOD!!! it works and saved me hours of frustration!
Kinda sad actually... had I used php in the last 3 years I would have remembered this and not had to crib from someone else ;) If it works, mark it the solution so others know.
Andrew Backer
oops I said that too soon, it works fine when testing the value I get from the database. The trouble is that in my php page I also get the value from $_REQUEST['variable'], when it is 1 (eg. test.php?test=1), mysql_bit returns false!! any solution?
return ord($bit)==1 || $bit==1;
Mike Sherov
Mike: i guess that 'll work too, I have a version (see Edit) that works biased toward true