I have a boolean column in a PostgreSQL table. In pgAdmin III, the table view shows 'TRUE' and 'FALSE' for the column. When I do a SQL 'select *', that other window shows 't' and 'f'. Is this some configuration problem? Shouldn't it also show 'TRUE' and 'FALSE'?
Then we come to PHP. I have the following code to deal with this boolean (actually I'm doing something different, but simplified it here):
$q = "select * from tax where id = $1";
$res = pg_query_params($conn,$q,[$id]);
if ($res) {
$row = pg_fetch_array($res,NULL,PGSQL_ASSOC);
$valido = $row['valido'];
echo $valido; // prints 'f' (== 'FALSE' on database)
if ($valido) {
echo 'valid'; // gets here
} else {
echo 'invalid';
}
}
The database says 'FALSE', php reads 'f' and treat it as 'TRUE'. Is this some faulty configuration, or php always reads a boolean value as a text interpreted as the opposite of the original value?
Let's face it:
This is specified by the PHP documentation in the "returned values" of the different fetch functions. here and here.
If you want these results to be cast to PHP equivalent types, you must set up a converter system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With