PHP turns every value it gets from the database into a string, this is not a problem for php as it is a very weakly typed language resulting in stuff like
Lua on the other hand is not that weakly typed and although it happily converts strings and numbers when working on them, it does NOT do that when comparing.
This means that the if statement will never become true and thus a character will never be returned. All in all the bug was caused by 3 languages working slightly diffrent from each other:
MYSQL, as it can't store real booleans.
PHP for converting everything it gets from the database into strings and also by making it no problem thus very easy to forget that that is happening
Lua for converting strings and ints only when working on them and not doing so when doing comparisons.