Casting MySQL bit type at PHP runtime
At some point in your project that you think represent boolean in your data structure as a mysql bit was a good idea, yet you do not find out because after a query to the database through PHP your bit does not behave like a boolean as you were expecting.
There are three ways you can do with a bit mysql behaves as a boolean:
At runtime in php:
$bitValue = ($bitValue == 0x01);
or
ord($bitvalue)
or in your query:
SELECT CAST (AS bitfield unsigned int) FROM ...
I hope it helps you.
Written by Arthur Barros
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#