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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.