I had no problems working with MySQL's BIT data type on a Windows environment with PHP and PDO. The only trick that I used was to cast it to int.
But when I uploaded the code to a Linux server, then I wasn't able to see those BIT values: I was getting a square character.
After searching for this, I've found this answer by Marc B, which coupled with Stanimir Stoyanov's comment I ended up doing this for both Windows and Linux and it's working great
CODE FOR DISPLAY
//linux OR windows
$display = ($value_from_db === chr(0x01) || $value_from_db == 1) ? 1 : 0;
CODE FOR SAVING
//both platforms
$value_for_db = ($display == 1) ? 0x01 : 0x00;
So my questions are:
- Are both platforms indeed treating this data type differently?
- Or is it a specific programm issue? (php, apache, mysql)
- Is this the correct way to address this issue? Maybe there's another approach
Windows 7: PHP 5.6.10, Apache 2.4.12, MySQL 5.6.26
Debian Wheezy: PHP 5.5.30, Apache 2.2.22, MySQL 5.6.25