RE: [PHP-DEV] PostgreSQL driver handles boolean values incorrectly...
| From: | Michael Sims | Date: | Sun, 07 Nov 2004 18:38:06 +0000 |
| Subject: | RE: [PHP-DEV] PostgreSQL driver handles boolean values incorrectly... | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13767@lists.php.net to get a copy of this message | ||
Sean Chittenden wrote:
> A boolean value is returned as the strings 't' and 'f', not the
> constants true and false. This presents all kinds of interesting
> oddities for code that does something like:
[...]
You're probably already aware of this, but you can use a bit(1) field as a
boolean and this will map to PHP values that will allow you to check for
truth in conditionals. Personally I do that instead of using Postgres's
boolean since other database systems I've worked with don't have a boolean
type, but they all have a bit type. Although I agree that it would be nice
for PHP to map pg's boolean to PHP's boolean...
> The same problem lies with the NULL value, which IMHO, should be
> mapped to the constant NULL, not the string 'NULL'.
I was unable to reproduce this. The following code:
$r = pg_query($dbh, "create table test (field1 varchar(10))");
$r = pg_query($dbh, "insert into test values (NULL)");
$r = pg_query($dbh, "select field1 from test");
$row = pg_fetch_row($r);
var_dump($row);
$r = pg_query($dbh, "drop table test");
outputs:
array(1) {
[0]=>
NULL
}
On PHP 4.3.9, Postgresql 7.4.5, running on Linux (Debian Sarge). If you get
different results perhaps you've uncovered a bug that should be reported...