php - Returning non-integer values in table for tinyint(1) Boolean data type -
i'm going using tinyint(1) / boolean datatype field in database (mysql) represent 2 values 'solo' , 'dual', 1 equal dual , 0 equal solo.
however, i'm wondering how display in table. since data stored 1 , 0 in database, how change corresponding 'dual' or 'solo' when creating tables using html, mysql, , php?
not asking code wondering if possible before using boolean datatype. thanks
with simple function:
function from_db_bool($bool){ return $bool ? 'dual' : 'solo'; } function to_db_bool($string){ return strtolower($string) == 'dual' ? 1 : 0; }
when inserting, use to_db_bool()
when printing out db use from_db_bool()
Comments
Post a Comment