note 85344 added to function.pg-fetch-assoc
| From: | strata_ranger at hotmail dot com | Date: | Tue, 26 Aug 2008 22:01:00 +0000 |
| Subject: | note 85344 added to function.pg-fetch-assoc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143848@lists.php.net to get a copy of this message | ||
In a bit of follow-up to Luke's note about SQL booleans (this was a painful thing to learn the
hard way), a relatively easy workaround is to typecase the boolean columns to integer inside the
query, e.g:
<?php
// Assuming 'foo' is a table column of type boolean
$res = pg_query("Select foo as foo1, foo::integer as foo2 from bar");
$data = pg_fetch_assoc($res);
if ($data['foo1']) echo 'foo1 = TRUE'; // Doesn't work as expected (string
't' and string 'f' both evaluate as TRUE)
if ($data['foo2']) echo 'foo2 = TRUE'; // Works as expected (string
'0' evaluates as FALSE)
?>
----
Server IP: 69.147.83.197
Probable Submitter: 76.2.28.137
----
Manual Page -- http://www.php.net/manual/en/function.pg-fetch-assoc.php
Edit -- https://master.php.net/note/edit/85344
Del: integrated -- https://master.php.net/note/delete/85344/integrated
Del: useless -- https://master.php.net/note/delete/85344/useless
Del: bad code -- https://master.php.net/note/delete/85344/bad+code
Del: spam -- https://master.php.net/note/delete/85344/spam
Del: non-english -- https://master.php.net/note/delete/85344/non-english
Del: in docs -- https://master.php.net/note/delete/85344/in+docs
Del: other reasons-- https://master.php.net/note/delete/85344
Reject -- https://master.php.net/note/reject/85344
Search -- https://master.php.net/manage/user-notes.php