MySQL bit value in PHP not working
I have a bit type value hasFreePackage
in a database that stores 1
or 0
.
Here is my code below. This works on my localhost, but whenever I try to upload to a live server, this code doesn't work.
public function checkBitValue($hasFreePackage)
{
$hasFreePackage= ($hasFreePackage== 0x01)
if($hasFreePackage==1)
return 1;
else
return 0;
}
As a live server it is a linux platform and I am running windows on my local machine. my code works on windows but not linux. So I changed the code to this code.
public function checkBitValue($hasFreePackage)
{
$FreePackage= ($hasFreePackage== 0x01)
if($FreePackage==1)
return 1;
elseif(ord($FreePackage==1))
return 1;
else
return 0;
}
but still doesn't work. I am using yii 1.1 php framework and php versions are different. Linux is 5.2.0 and local (windows) is 5.7
Even easier:
{
return $hasFreePackage ? 1 : 0;
}
Or, more clearly:
{
return $hasFreePackage ? TRUE : FALSE;
}
Justification: 0 - FALSE; nonzero numbers are TRUE.
Better yet, keep this in mind and don't get in the way of checking for true / false for true / false!
Warning: NULL
and ''
dirty logic like this. Hence, the rationale only spoke of numbers.
source to share