What is the best way for boolen statement to know it is true or false?
In MYSQL database after select boolean it is showing tinyint(1)
but the issue is when in database the value is 1,
I use if($var == 1)
result is false
and if($var == "1")
is true
.
But in my localhost (WAMP Server)
if($var == 1)
is true
I am very confused the MYSQL version issue? By the way I am using laravel framework...
MySQL has very little to do with your problem and neither does laravel.
In php, 1 is true, "1" is true, 0 is false, and "0" is false. Therefore, you should be able to write it as if ($var) {}
unless you abhor such conventions.
Type cast $var
to int
when you are assigning $var
and then do the comparison. Example below:
$var = (int) $result['db_field_name'] // $result indicates the database value
if($var == 1) {
}
I am sure, this will work on every machine.