I’m trying to retrieve a bitmask from a MySql DB table in PHP. I use the meekro db library to interact with the database.
Here is the code used to query the DB:
$query = DB::queryFirstRow($select, $tid);
$dm = $query['dayMask'];
var_dump($dm);
The row returned by the database contains a column named dayMask, which is defined as BIT(7) with the value 0110001.
The above code prints string(3) "127" which makes no sense for me. The decimal representation of the mask is 49, 127 corresponds to 1111111.
What am I doing wrong? How can I retrieve a bitmask value from the DB in PHP?
Solved.
The problem was related to the SQL statement used to insert new values.
As I discovered, starting from the example provided by VolkerK, to insert bit value in MySQL I should use the following syntax (from here):
Using this syntax my code works.
The strange thing is that inserting the value as a literal doesn’t result in any error or warning from MySQL. Moreover, phpmyadmin displays the field correctly when inserted with the wrong syntax, while it displays the value incorrectly when inserted with the right syntax.