I am really torn on what to do with this. Over the past 10 years, I just agreed with this, but I think it's time to decide the right way to solve this problem.
According to the internet, MySQL does not support its own data type, which makes sense why, when I select "BOOLEAN", I see that the column ends as tinyint (1).
I have no problem storing data like tinyint with a 1 or 0 value, however I have a problem with the fact that when I select a lot of rows from the database with this column, I get the string "1" or "0" instead of PHP native bool true / false. Of course, PHP can treat this variable as a boolean, because it seems to automatically know what I want to do when I do == 0 or == 1 or even == '0' or == '1' if I "I really feel it."
So here I go, take this data and run it in the PHP json_encode function and output it when the Backbone / Handlebars implementation makes an ajax call and gets a beautiful beautiful JSON object (usually with many string data in it) with this: {"myVariable":"1"} or this is {"myVariable":"0"} .
I am sure you can see the problem with the desire to do something like this in Handlebars.js:
{{#if myVariable}} Do this {{else}} Do that {{/if}}
Now I really DO NOT want to do something like this:
<?php for($i = 0; $i < count($recordSet); $i++) { $recordSet[$i]['myVariable'] = (bool)$recordSet[$i]['myVariable']; } ?>
Being that the application I am creating contains thousands of columns in a database that I cannot (or just have to) just run the above code for each column that I want to maintain as bool in my javascript. And I really don't want to do this (although it probably would have been easier)
Handlebars.registerHelper('ifTrue', function(a, b) {
Is there a better way? I am using a code igniter ... can the database class be modified in some way to detect a tinyint (1) column and automatically drop it in the bool, and then just do it until MySQL supports the true Boolean column? I know that they are planning this, but ...