Good practice in comparing 0/1 values from mysql in php #53916
Unanswered
bulletproof-coding
asked this question in
General
Replies: 1 comment 6 replies
-
Have you tried using an Attribute Cast of |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Take this type of column for example
is_enabled enum('1','0') COLLATE utf8mb3_unicode_ci DEFAULT '0',
It will play tricks on you if you update it to 0 as int in mysql 8 ( It will become empty string).
The laravel migration with boolean converts it like:
is_enabled tinyint(1) DEFAULT '0',
In both cases this is what saved me from having to fix bugs in code:
So never compare with anything but 1 as string.
UPDATE
the db migration converted '' to 0, '1' to 1 and '0' to, pay attention 2 :))))
Beta Was this translation helpful? Give feedback.
All reactions