Обсуждение: What's wrong with this? (Pt II)
Folloing a number of suggestions from various people I tried
ammending my original code and now have:-
<HTML>
<HEAD>
<TITLE>pg_test</TITLE>
</HEAD>
<BODY>
<?
$connectid = pg_connect("194.164.53.200", "5432", "postgres");
$query = "SELECT townName FROM towns";
$result = pg_exec($connectid, $query);
$row = pg_fetch_array($result,$row);
print("using element 0 :- \n");
print($row[0]);
print("<BR>");
print("using double quotes :- \n");
print($row["townName"]);
print("<BR>");
print("using single quotes :- \n");
print($row['townName']);
print("<BR>");
print("using no quotes :- \n");
print($row[townName]);
print("<BR>");
print("using printf :- \n");
printf("%s\n",$row->townName);
print("<BR>");
?>
And this is what the output looks like:-
using element 0 :- leeds
using double quotes :-
using single quotes :-
using no quotes :-
using printf :-
So I'm no wiser reallly...
Can anyone try running this snippet on their own system and show
me what happens?
It's coded to point at an host which _ought_ to be able to
service a query.
--
John
On Mon, Jan 22, 2001 at 01:31:16AM +0000, some SMTP stream spewed forth:
*snip*
> <?
> $connectid = pg_connect("194.164.53.200", "5432", "postgres");
This syntax is deprecated. What version of PHP are you using?
The more correct syntax would be
pg_connect("host=194.164.53.200 port=5432 user=<user>"
." password=<password> dbname=<database>");
http://www.php.net/manual/function.pg-connect.php
The same is true for pg_pconnect().
> $query = "SELECT townName FROM towns";
> $result = pg_exec($connectid, $query);
> $row = pg_fetch_array($result,$row);
What is the value of $row that you are passing to pg_fetch_array?
(That should be the number of the row *in the resultset* that you
want to retrieve.)
In addition, I recieved a pg_hba.conf error when I attempted to test
this script, using what you sent. Can you clarify what
the username, password, and database are supposed to be?
---
Warning: Unable to connect to PostgreSQL server: No pg_hba.conf entry for
host 63.147.13.10, user nobody, database postgres in
/depot/home/grasshacker/public_html/pg_test.php on line 10
---
gh
*snip*
> Can anyone try running this snippet on their own system and show
> me what happens?
Tried...did.
>
> It's coded to point at an host which _ought_ to be able to
> service a query.
It is not able to, at least, not in the context of this test.
>
> --
> John
Don't forget too that when you do a pgsql_fetch_array,
the way your are doing it, it will only pull the last
item. You need to make that in a while loop, so that
it will retreive all the rows of data.
Example:
while($row = pgsql_fetch_array($result))
{
echo $row["townName"];
}
This will display all the townName entries that were a part
of your query. (i.e., if there were 4 results returned, it would
display all 4 results, but only the column townName)
Hope this helps,
Andy Holman
GH wrote:
>
> On Mon, Jan 22, 2001 at 01:31:16AM +0000, some SMTP stream spewed forth:
> *snip*
> > <?
> > $connectid = pg_connect("194.164.53.200", "5432", "postgres");
>
> This syntax is deprecated. What version of PHP are you using?
> The more correct syntax would be
> pg_connect("host=194.164.53.200 port=5432 user=<user>"
> ." password=<password> dbname=<database>");
> http://www.php.net/manual/function.pg-connect.php
> The same is true for pg_pconnect().
>
> > $query = "SELECT townName FROM towns";
> > $result = pg_exec($connectid, $query);
> > $row = pg_fetch_array($result,$row);
>
> What is the value of $row that you are passing to pg_fetch_array?
> (That should be the number of the row *in the resultset* that you
> want to retrieve.)
>
> In addition, I recieved a pg_hba.conf error when I attempted to test
> this script, using what you sent. Can you clarify what
> the username, password, and database are supposed to be?
>
> ---
> Warning: Unable to connect to PostgreSQL server: No pg_hba.conf entry for
> host 63.147.13.10, user nobody, database postgres in
> /depot/home/grasshacker/public_html/pg_test.php on line 10
> ---
>
> gh
>
> *snip*
>
> > Can anyone try running this snippet on their own system and show
> > me what happens?
> Tried...did.
> >
> > It's coded to point at an host which _ought_ to be able to
> > service a query.
>
> It is not able to, at least, not in the context of this test.
>
> >
> > --
> > John
On Mon, Jan 22, 2001 at 04:40:34AM -0500, info@i-developit.com wrote:
> Don't forget too that when you do a pgsql_fetch_array,
> the way your are doing it, it will only pull the last
> item. You need to make that in a while loop, so that
> it will retreive all the rows of data.
Yes, I am aware of that, but pulling any item appears to be proving a
hurdle...
> Example:
>
> while($row = pgsql_fetch_array($result))
> {
> echo $row["townName"];
> }
>
> This will display all the townName entries that were a part
> of your query. (i.e., if there were 4 results returned, it would
> display all 4 results, but only the column townName)
It appears that there is something fundamentally wrong.
Here's the full script:-
<HTML>
<HEAD>
<TITLE>pg_test</TITLE>
</HEAD>
<BODY>
<?
$connectid = pg_connect("194.164.53.200", "5432", "postgres");
$query = "SELECT townName FROM towns";
$result = pg_exec($connectid, $query);
while($row = pgsql_fetch_array($result))
{
echo $row["townName"];
}
?>
This is the response:-
Fatal error: Call to undefined function: pgsql_fetch_array() in test.php
on line 17
Line 17 => while($row = pgsql_fetch_array($result))
c:\>php -v
4.0.4pl1
Since this appears to be a PHP problem rather than anything specific to
Postges, I guess I should pursuit it elsewhwere. Is there anything like
a PHP-Novices mailing list anywhere?
> Hope this helps,
> Andy Holman
--
John
That's because the function should actually be,
pg_fetch_array(integer result, integer row)
When in doubt always check the php manual online
at www.php.net. As I said in an earlier e-mail on
this subject, I don't use the standard pgsql functions
within php, I use phpLIB. Sorry for typing the wrong
function, but I was close :)
--Andy
John Poltorak wrote:
>
> On Mon, Jan 22, 2001 at 04:40:34AM -0500, info@i-developit.com wrote:
> > Don't forget too that when you do a pgsql_fetch_array,
> > the way your are doing it, it will only pull the last
> > item. You need to make that in a while loop, so that
> > it will retreive all the rows of data.
>
> Yes, I am aware of that, but pulling any item appears to be proving a
> hurdle...
>
> > Example:
> >
> > while($row = pgsql_fetch_array($result))
> > {
> > echo $row["townName"];
> > }
> >
> > This will display all the townName entries that were a part
> > of your query. (i.e., if there were 4 results returned, it would
> > display all 4 results, but only the column townName)
>
> It appears that there is something fundamentally wrong.
>
> Here's the full script:-
>
> <HTML>
> <HEAD>
> <TITLE>pg_test</TITLE>
> </HEAD>
> <BODY>
>
> <?
>
> $connectid = pg_connect("194.164.53.200", "5432", "postgres");
>
> $query = "SELECT townName FROM towns";
>
> $result = pg_exec($connectid, $query);
>
> while($row = pgsql_fetch_array($result))
> {
> echo $row["townName"];
> }
>
> ?>
>
> This is the response:-
>
> Fatal error: Call to undefined function: pgsql_fetch_array() in test.php
> on line 17
>
> Line 17 => while($row = pgsql_fetch_array($result))
>
> c:\>php -v
> 4.0.4pl1
>
> Since this appears to be a PHP problem rather than anything specific to
> Postges, I guess I should pursuit it elsewhwere. Is there anything like
> a PHP-Novices mailing list anywhere?
>
> > Hope this helps,
> > Andy Holman
>
> --
> John