From: Chris <dmagick@gmail.com>
To: Thom Brown <thombrown@gmail.com>
Cc: pgsql-php@postgresql.org, PGSQL Mailing List <pgsql-general@postgresql.org>
Subject: Re: [PHP] PHP and PostgreSQL boolean data type
Date: Thu, 11 Feb 2010 08:56:36 +1100
Message-ID: <4B732B94.20007@gmail.com> (raw)
In-Reply-To: <bddc86151002100404o76e1acc9r469d82a49284b7b5@mail.gmail.com>
References: <bddc86151002100404o76e1acc9r469d82a49284b7b5@mail.gmail.com>
Thom Brown wrote:
> Hi,
>
> A long-standing problem we've had with PostgreSQL queries in PHP is
> that the returned data for boolean columns is the string 'f' instead
> of the native boolean value of false.
>
> An obvious example of this would be for a table with users and their
> boolean registered status:
>
> Select user, registered From users;
>
> Then getting a row from the result would reveal: array('user' =>
> 'thomb', registered => 'f');
That's how postgres stores them, php doesn't understand the field is a
boolean.
# create table a(a int, b boolean);
# insert into a(a, b) values (1, true);
# insert into a(a, b) values (2, false);
# SELECT * from a;
a | b
---+---
1 | t
2 | f
(2 rows)
Also while not in the "official" docs, it is a note from 2002:
http://www.php.net/manual/en/ref.pgsql.php#18749
and
http://www.php.net/manual/en/function.pg-fetch-array.php says
Each value in the array is represented as a string. Database NULL
values are returned as NULL.
> Another problem is with arrays, where they are difficult to parse as
> they also come through as plain strings with no binary alternative.
Haven't played with postgres arrays so can't say either way - but same
as above, php just fetches the data.
There's an example that might help you -
http://www.php.net/manual/en/ref.pgsql.php#89841
--
Postgresql & php tutorials
http://www.designmagick.com/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: dmagick@gmail.com, thombrown@gmail.com, pgsql-general@postgresql.org
Subject: Re: [PHP] PHP and PostgreSQL boolean data type
In-Reply-To: <4B732B94.20007@gmail.com>
References: <bddc86151002100404o76e1acc9r469d82a49284b7b5@mail.gmail.com> <4B732B94.20007@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox