note 69825 added to function.pg-fetch-result
| From: | AlanUKennington at osu1 dot php dot net | Date: | Fri, 22 Sep 2006 12:16:50 +0000 |
| Subject: | note 69825 added to function.pg-fetch-result | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117417@lists.php.net to get a copy of this message | ||
In order to use upper case in pg_fetch_result column names, it is apparently necessary to include
explicit quotation marks.
Thus when I do this sort of thing:
$res = pg_query(...);
$ncols = pg_num_fields($res);
for ($j = 0; $j < $ncols; ++$j) {
$colname[$j] = pg_field_name($res, $j);
$name = htmlspecialchars($colname[$j]);
print("Column $j name = \"$name\"\n");
$value = htmlspecialchars(pg_fetch_result($res, 0, $colname[$j]));
print("Column \"{$colname[$j]}\" value = \"$value\"\n");
}
I get this sort of thing:
[....]
Warning: pg_fetch_result() [function.pg-fetch-result]: Bad column offset specified in /.../view.php
on line 247
Column 8 name = "VEC index"
Column "VEC index" value = ""
But if I change the $value line to this:
$value = htmlspecialchars(pg_fetch_result($res, 0, "\"$colname[$j]\""));
I get this:
[...]
Column 8 name = "VEC index"
Column "VEC index" value[0] = "47"
In my opinion, pg_fetch_result(...) should use the quotes already. In other words, this may be a bug
in the PHP postgres library. It does not seem to be a documented feature of pg_fetch_result()
although the postgresql manual documents it under "SQL syntax", "Lexical
structure".
PHP version 5.1.4.
psql version 8.1.4.
----
Server IP: 203.16.234.91
Probable Submitter: 58.6.65.66
----
Manual Page -- http://www.php.net/manual/en/function.pg-fetch-result.php
Edit -- https://master.php.net/note/edit/69825
Del: integrated -- https://master.php.net/note/delete/69825/integrated
Del: useless -- https://master.php.net/note/delete/69825/useless
Del: bad code -- https://master.php.net/note/delete/69825/bad+code
Del: spam -- https://master.php.net/note/delete/69825/spam
Del: non-english -- https://master.php.net/note/delete/69825/non-english
Del: in docs -- https://master.php.net/note/delete/69825/in+docs
Del: other reasons-- https://master.php.net/note/delete/69825
Reject -- https://master.php.net/note/reject/69825
Search -- https://master.php.net/manage/user-notes.php