Jump to content

Recommend using true/false for Boolean values?


NotionCommotion

Recommended Posts

MySQL cannot store Boolean values and thus I use 0/1.  Is there much benefit to cast them as Boolean immediately after querying the database, do whatever PHP processing is required, and then convert them back to 0/1 before writing to the database?  One benefit is I can type declare my arguments, but I am debating whether it is worth it.  Thanks

Link to comment
Share on other sites

23 minutes ago, gw1500se said:

My SQL does accept the constants "TRUE" and "FALSE" if that helps.

Thank you.  I was unaware. Are you saying one can do $pdo->prepare($sql)->execute([123, true, false]); ?

6 minutes ago, ginerjm said:

PHP does inherently treat the MySQL values of 0 and 1 as true and false.  So what you are asking has already been answered.

I am not asking from a MySQL prospective but a PHP prospective.  In the past, I never explicitly declared variable argument and returned types, and found that it got me  in a lot of trouble.  I am asking whether it is good practice to perform boolval($mysqlOutput) or (bool) $mysqlOutput on data received from MySQL before processing the data with PHP.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.