note 91472 added to function.pg-fetch-all
| From: | strata_ranger at hotmail dot com | Date: | Thu, 11 Jun 2009 15:00:41 +0000 |
| Subject: | note 91472 added to function.pg-fetch-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156777@lists.php.net to get a copy of this message | ||
Be aware that pg_fetch_all() is subject to the same limitations as pg_fetch_assoc(), in that if your
query returns multiple columns with the same name (or alias) then only the rightmost one will be
returned in the associative array, other ones will not.
A simple example:
<?php
$res = pg_query(
"SELECT a.*, b.* -- Fetch all columns from both tables
FROM table1 AS a
LEFT OUTER JOIN table2 as b
USING (column)"
);
$rows = pg_fetch_all($res);
?>
In this example, since we're selecting columns via *, if any columns from table2 share the same
names as those in table1, they will be the ones returned despite that table2 (as the optional side
of an outer join) may return NULL values.
This is not a bug, just a limitation of associative arrays in general, and is easy enough to avoid
by structuring your queries carefully and using column aliases to avoid confusion.
----
Server IP: 69.147.83.197
Probable Submitter: 76.2.25.104
----
Manual Page -- http://www.php.net/manual/en/function.pg-fetch-all.php
Edit -- https://master.php.net/note/edit/91472
Del: integrated -- https://master.php.net/note/delete/91472/integrated
Del: useless -- https://master.php.net/note/delete/91472/useless
Del: bad code -- https://master.php.net/note/delete/91472/bad+code
Del: spam -- https://master.php.net/note/delete/91472/spam
Del: non-english -- https://master.php.net/note/delete/91472/non-english
Del: in docs -- https://master.php.net/note/delete/91472/in+docs
Del: other reasons-- https://master.php.net/note/delete/91472
Reject -- https://master.php.net/note/reject/91472
Search -- https://master.php.net/manage/user-notes.php