#45152 [Opn->Bgs]: Boolean variables returned by pg_fetch_array
ID: 45152
Updated by: hholzgra@php.net
Reported By: ernesto_sanz at hotmail dot com
-Status: Open
+Status: Bogus
Bug Type: PostgreSQL related
Operating System: Ubuntu 7.04
PHP Version: 5.2.6
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
pg_fetch_*() returns boolean values in the same way as psql displays
them in query results: as the strings 't' for true and 'f' for false.
Previous Comments:
------------------------------------------------------------------------
[2008-06-03 23:24:21] ernesto_sanz at hotmail dot com
Description:
------------
I'm using Ubuntu Feisty Fawn 7.04 with Apache with PHP 5.2.4 and
Postgres v.8.2.4.
I have noticed that, when querys are run, logical variables are not
correctly assigned.
E.g. being 'lists' the table defined by the SQL sentence:
CREATE TABLE lists
(
active boolean NOT NULL DEFAULT true,
reference serial NOT NULL,
caducated boolean NOT NULL DEFAULT false,
name character varying(100) NOT NULL,
...
)
and the PHP code
// creation of the SQL sentence
$consulta="SELECT * FROM lists WHERE ((referencie=".$mykey.") AND
(active=true))";
// Execution
$result = pg_query($consulta)
or die('Error in SQL query:'.pg_last_error());
if (pg_num_rows($resultado)>0) { {
$line = pg_fetch_array($result, null, PGSQL_ASSOC);
if ($line["caducated"]==true)
{ ... -code executed if condition=true- }
else
{ ... -code executed if condition=false- }
...
I realized that the 'else' code was executed ALWAYS. It did not matter
if the condition was $line["caducated"]==True, or TRUE, or 1, or False
or FALSE or 0.
I noticed that logical variables are assigned to 't' or 'f' instead of
'true' or 'false' (or numbers) and their type is not correct (the
result of gettype($line["caducated"]) is "string"- , so, the only way to
execute correctly the 'if' sentence is by typing "if
($line["caducated"]=='t')" (or
"$line["caducated"]=='f'")
which violates the reference syntax of PHP, that states that to specify
a boolean literal we have to use keywords TRUE or FALSE (both
case-insensitive).
Also, sometimes, asignation of variables inside the if or else blocks
is made in a wrong way.
------------------------------------------------------------------------
[2008-06-02 21:19:31] ernesto_sanz at hotmail dot com
Description:
------------
I'm using Ubuntu Feisty Fawn 7.04 with Apache with PHP 5.2.4 and
Postgres v.8.2.4.
I have noticed that, when querys are run, logical variables are not
correctly assigned.
E.g. being 'lists' the table defined by the SQL sentence:
CREATE TABLE lists
(
active boolean NOT NULL DEFAULT true,
reference serial NOT NULL,
caducated boolean NOT NULL DEFAULT false,
name character varying(100) NOT NULL,
...
)
and the PHP code
// creation of the SQL sentence
$consulta="SELECT * FROM lists WHERE ((referencie=".$mykey.") AND
(active=true))";
// Execution
$result = pg_query($consulta)
or die('Error in SQL query:'.pg_last_error());
if (pg_num_rows($resultado)>0) { {
$line = pg_fetch_array($result, null, PGSQL_ASSOC);
if ($line["caducated"]==true)
{ ... -code executed if condition=true- }
else
{ ... -code executed if condition=false- }
...
I realized that the 'else' code was executed ALWAYS. It did not matter
if the condition
was $line["caducated"]==True, or TRUE, or 1, or False or FALSE or 0.
I noticed that logical variables are assigned to 't' or 'f' instead of
'true' or 'false' (or numbers)
(although their type -boolean- is correct- and, that the only way to
execute correctly the 'if' sentence
is by typing "if ($line["caducated"]==t)" (or
"$line["caducated"]==f")
which violates the reference syntax
of PHP, that states that to specify a boolean literal we have to use
keywords TRUE or FALSE (both case-insensitive).
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45152&edit=1
Thread (3 messages)