i have a table field that's type is tinyint
. so the values in mysql can be stored as 1
for true
and 0
for false
.
i used php's mysqli module to fetch the data. e.g.
$result = $mysqli->query("SELECT * FROM table_x_y");
$row = $result->fetch_assoc()
now i get a data row of the table. but the fields with the type tinyint
are integers not boolean.
the problem come with php's json_encode
. i want to create a JSON object. But the boolean fields are still integer (in $row
) and the encode function treated them as integer not as a boolean.
the result of the json object looks like
[
{
"foo": 1,
"bar": 2
},
{
"foo": 0,
"bar": 1
}
]
but i should look like
[
{
"foo": true,
"bar": 2
},
{
"foo": false,
"bar": 1
}
]
Info
foo
datatype is tinyint
.
bar
datatype is int