I got this piece of function that updates an account with 1 or 0,
note that the account_status has a data type of boolean.
I understand that $this->db->query(); returns TRUE or FALSE in write queries,
but i am having trouble, because when i tried to put a non boolean value on account_status, still the response is success, but obviously it will not update because the data is not boolean.
public function approve_account($id='0'){
if($id == '0' OR $id== ''){
return FALSE;
}else{
try{
$id = (int)htmlentities($id,ENT_COMPAT,'UTF-8');
$sql= "UPDATE elibrary.elib_user_account e
SET account_status = 'hg'
WHERE t_user_id = ?
LIMIT 1;";
if($this->db->query($sql,$id) === TRUE){
echo 'sucess';
}else{
echo 'FAIL';
}
}catch(Exception $e){
echo $e;
}
}
}
MySQL does not have a native
booleantype, booleans are represented astinyint(1). Storing string values in a numeric column would coerce them to a numeric value — in your case, the string'hg'is not a valid integer, and is coerced to the value0, which is stored in theaccount_statuscolumn and further interpreted asfalse. If your string contains a valid number, e.g.'5', it would be stored as the integer value5, which is consideredtruefor boolean operations.