Skip site navigation (1) Skip section navigation (2)

Re: [PHP] PHP and PostgreSQL boolean data type

From: Chris <dmagick(at)gmail(dot)com>
To: Thom Brown <thombrown(at)gmail(dot)com>
Cc: pgsql-php(at)postgresql(dot)org, PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: [PHP] PHP and PostgreSQL boolean data type
Date: 2010-02-10 21:56:36
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-generalpgsql-php
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 

# 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:

and 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 -

Postgresql & php tutorials

In response to

pgsql-php by date

Next:From: Torsten ZühlsdorffDate: 2010-02-11 07:42:35
Subject: Re: PHP and PostgreSQL boolean data type
Previous:From: Torsten ZühlsdorffDate: 2010-02-10 14:15:18
Subject: Re: PHP and PostgreSQL boolean data type

pgsql-general by date

Next:From: paul eDate: 2010-02-11 00:15:56
Subject: windows7 login- user account
Previous:From: Baron SchwartzDate: 2010-02-10 18:42:39
Subject: Re: Logging statement/duration on the same line

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group