My MySQL table contains tinyint (1), which I use to store true or false.
I have the following PHP variables:
$name = ''; $description = ''; $active = true;
Now my SQL query is as follows:
$query = "INSERT into my_table (my_name, my_description, active) VALUES ('$name', '$description', $active) ";
This will only work if my value for $ active is true. Once the active variable is false, php inserts an empty string instead of 0, and therefore the request will fail.
What is the best method to use false in such a query?
Should I manually convert false to string '0'? Is it better to use bites on the PHP side right away? in other words declare: $ active = '1'; or can I somehow make PHP always convert false to string '0'?
Thanks michael
source share