0

I've recently done a new server install, and it seems on the old one I had sql_mode='' in my my.cnf file. I've removed that now, so I have the default STRICT_TRANS_TABLES and the other default options.

Sadly though, that STT declaration is breaking my php PDO code where I explicity force type on my booleans, and send true/false through to the database.

I guess before these were being silently converted to 1/0.

Are these my only options:

  1. change my PHP variables ($isArchived etc) from the semantic niceness of true/false to 1/0.

  2. reinstate sql_mode = ''

Or am I missing something? My columns are defined as tinyint(1) - that used to be the best we could do with MySQL, and I don't THINK there's a boolean type, even now. What's the best practice? Thank you!

edit:

I realise now it's just false it fails on. It happily converts true to 1, but for some reason sees false as '' and balks. Could this be a problem in my PHP code rather than MySQL...

  • 1
    In MySQL TRUE is an alias of 1 and FALSE is an alias of 0. This is documented. If some problem occures it can be (1) you transfer them as string literals, not keywords (2) client-side issue. – Akina Nov 17 at 11:26
  • I've come to the same conclusion, so am trying a different question... stackoverflow.com/questions/64874468/… – Codemonkey Nov 17 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.