Tuesday, September 27, 2011

MySQL BIT in PHP

MySQL BIT in PHP

Ok, if you subscribe to my blog for personal reasons, this isn’t very relevant to you, but for those of you here for the programming, on a recent project I had some problems getting the BIT field in MySQL to be interpreted as a boolean in PHP. There are a couple of discussions on the net about it here and here, but I couldn’t find any simply stated solutions on the net. So here’s what I ended up doing. You can also download the file here, rename the file .php to use it.

function mysql_bit($bit) {
return ord($bit) == 1;
}

If you found any of the software useful, please consider supporting its further developement by donating.

No comments:

Post a Comment