pg_result

Started by David Zampesealmost 28 years ago8 messagesgeneral
Jump to latest
#1David Zampese
davez@istand.com

I have looked all over the site and I can not find good description for
'pg_result' I am having this problem. My database and everthing is
working fine but when I try to run a query from an html webpage it is not
working and I believe it is my 'pg_result' command. I have a table with
5-6 columns of information and I want total records to be selected. I then
reference the call to a variable and call it further in my HTML, but
nothing prints up. I have tried naming all the fields where 'row1' is
below but it also doesn't work. I am not getting any errors and html
prints back except for any values for '$rows', not even the row1 values
will come back. My query command works fine in psql.
Does anyone see my problem?

$result = pg_Exec($conn, "$query");
if (!$result);
echo "An error occured inserting information into our database.\n";
exit;
else;
pg_close ($conn);
endif;
$rows = pg_result($result,0,"row1");

Thanks in advance,
Dave

#2Jackson, DeJuan
djackson@cpsgroup.com
In reply to: David Zampese (#1)
RE: [GENERAL] pg_result

I have looked all over the site and I can not find good
description for
'pg_result' I am having this problem. My database and everthing is
working fine but when I try to run a query from an html webpage it is
not
working and I believe it is my 'pg_result' command. I have a table
with
5-6 columns of information and I want total records to be selected. I
then
reference the call to a variable and call it further in my HTML, but
nothing prints up. I have tried naming all the fields where 'row1' is
below but it also doesn't work. I am not getting any errors and html
prints back except for any values for '$rows', not even the row1
values
will come back. My query command works fine in psql.
Does anyone see my problem?

$result = pg_Exec($conn, "$query");
if (!$result);
echo "An error occured inserting information into our
database.\n";
exit;
else;
pg_close ($conn);
endif;
$rows = pg_result($result,0,"row1");

Thanks in advance,
Dave

Close the connection after you are done retrieving the results.
-DEJ

#3David Zampese
davez@istand.com
In reply to: Jackson, DeJuan (#2)
RE: [GENERAL] pg_result

I tried it but it still didn't work.
Thanks,
Dave

Date: Thu, 25 Jun 1998 10:46:27 -0500
From: "Jackson, DeJuan" <djackson@cpsgroup.com>
To: davez@istand.com, pgsql-general@postgreSQL.org
Subject: RE: [GENERAL] pg_result

I have looked all over the site and I can not find good
description for
'pg_result' I am having this problem. My database and everthing is
working fine but when I try to run a query from an html webpage it is
not
working and I believe it is my 'pg_result' command. I have a table
with
5-6 columns of information and I want total records to be selected. I
then
reference the call to a variable and call it further in my HTML, but
nothing prints up. I have tried naming all the fields where 'row1' is
below but it also doesn't work. I am not getting any errors and html
prints back except for any values for '$rows', not even the row1
values
will come back. My query command works fine in psql.
Does anyone see my problem?

$result = pg_Exec($conn, "$query");
if (!$result);
echo "An error occured inserting information into our
database.\n";
exit;
else;
pg_close ($conn);
endif;
$rows = pg_result($result,0,"row1");

Thanks in advance,
Dave

Close the connection after you are done retrieving the results.
-DEJ

#4Jason
neumeier@bright.net
In reply to: David Zampese (#3)
RE: [GENERAL] pg_result

$result points to the result structure. I.e.

$result_status = $result->resultStatus

Returns the status of the result. For comparing the status you
may use one of the following constants depending upon the
command executed:

- PGRES_EMPTY_QUERY
- PGRES_COMMAND_OK
- PGRES_TUPLES_OK
- PGRES_COPY_OUT
- PGRES_COPY_IN
- PGRES_BAD_RESPONSE
- PGRES_NONFATAL_ERROR
- PGRES_FATAL_ERROR

See Pg.pm for all of the result structure.

Show quoted text

-----Original Message-----
From: Jackson, DeJuan [SMTP:djackson@cpsgroup.com]
Sent: Thursday, June 25, 1998 11:46 AM
To: davez@istand.com; pgsql-general@postgreSQL.org
Subject: RE: [GENERAL] pg_result

I have looked all over the site and I can not find good
description for
'pg_result' I am having this problem. My database and everthing is
working fine but when I try to run a query from an html webpage it

is

not
working and I believe it is my 'pg_result' command. I have a table
with
5-6 columns of information and I want total records to be selected.

I

then
reference the call to a variable and call it further in my HTML, but
nothing prints up. I have tried naming all the fields where 'row1'

is

below but it also doesn't work. I am not getting any errors and

html

prints back except for any values for '$rows', not even the row1
values
will come back. My query command works fine in psql.
Does anyone see my problem?

$result = pg_Exec($conn, "$query");
if (!$result);
echo "An error occured inserting information into our
database.\n";
exit;
else;
pg_close ($conn);
endif;
$rows = pg_result($result,0,"row1");

Thanks in advance,
Dave

Close the connection after you are done retrieving the results.
-DEJ

#5Jackson, DeJuan
djackson@cpsgroup.com
In reply to: Jason (#4)
RE: [GENERAL] pg_result

$result points to the result structure. I.e.

$result_status = $result->resultStatus

Returns the status of the result. For comparing the status you
may use one of the following constants depending upon the
command executed:

- PGRES_EMPTY_QUERY
- PGRES_COMMAND_OK
- PGRES_TUPLES_OK
- PGRES_COPY_OUT
- PGRES_COPY_IN
- PGRES_BAD_RESPONSE
- PGRES_NONFATAL_ERROR
- PGRES_FATAL_ERROR

See Pg.pm for all of the result structure.

I believe that you are using PHP, and not PERL, to interface with
PostgreSQL. (Please refer to http://www.php.net)
Since I can't see the query I'll have to assume that the field name that
you are passing to pg_result is wrong. You might want to include the
query and tell us which column you are trying to retrieve.

Show quoted text

-----Original Message-----
From: Jackson, DeJuan [SMTP:djackson@cpsgroup.com]
Sent: Thursday, June 25, 1998 11:46 AM
To: davez@istand.com; pgsql-general@postgreSQL.org
Subject: RE: [GENERAL] pg_result

I have looked all over the site and I can not find good
description for
'pg_result' I am having this problem. My database and everthing

is

working fine but when I try to run a query from an html webpage it

is

not
working and I believe it is my 'pg_result' command. I have a

table

with
5-6 columns of information and I want total records to be

selected.

I

then
reference the call to a variable and call it further in my HTML,

but

nothing prints up. I have tried naming all the fields where

'row1'

is

below but it also doesn't work. I am not getting any errors and

html

prints back except for any values for '$rows', not even the row1
values
will come back. My query command works fine in psql.
Does anyone see my problem?

$result = pg_Exec($conn, "$query");
if (!$result);
echo "An error occured inserting information into our
database.\n";
exit;
else;
pg_close ($conn);
endif;
$rows = pg_result($result,0,"row1");

Thanks in advance,
Dave

Close the connection after you are done retrieving the results.
-DEJ

#6David Zampese
davez@istand.com
In reply to: Jackson, DeJuan (#5)
RE: [GENERAL] pg_result

Awe, I switched over to Perl, I forgot I started with a PHP
script. I get it to interact with the table and I read through perldocs
on Pg, but I still can not figure out how to print up the result.
I get this from it:
Result PG_result=SCALAR(0x810e178)
Ntuples 10
NFields 11
Status 0
ResultStatus 2
Command Status
E_Message

I am trying to get back 10 lines of information that each contain
11 fields. Do you know what variable I should set up. Do I need to set
up and array call since there are more than 1 line of data that I am
trying to call?

This is what I have:

#!/usr/local/bin/perl

use Pg;

$database = "inquiries";
$conn = Pg::connectdb("dbname = $database");

$query = "select * from sales where acctid = 'dave'";
$result = $conn->exec("$query");
# should check to see if status is ok if not fail it
$status = $conn->status;
$errorMessage = $conn->errorMessage;
$cmdStatus = $result->cmdStatus;

$result_status = $result->resultStatus;
$ntuples = $result->ntuples;
$nfields = $result->nfields;

# Return HTML page
print "Content-type: text/html\n\n";
print "<html>\n";
print "<body BGCOLOR=white>\n";
print "<center>\n";
print "<h2>Transactions to Date</h2>\n";
print "<table><tr><td>\n";
print "Result $result<br>\n";
print "Ntuples $ntuples<br>\n";
print "NFields $nfields<br>\n";
print "Status $status<br>\n";
print "ResultStatus $result_status<br>\n";
print "Command Status $cmdStatus <br>\n";
print "E_Message $errorMessage<br>\n";
print "</td></tr></table>\n";
print "</body>\n";
print "</html>\n";

exit;

#7Noname
dj@pelf.harvard.edu
In reply to: David Zampese (#6)
RE: [GENERAL] pg_result

--------- Received message begins Here ---------

I am trying to get back 10 lines of information that each contain
11 fields. Do you know what variable I should set up. Do I need to set
up and array call since there are more than 1 line of data that I am
trying to call?

This is what I have:

#!/usr/local/bin/perl

use Pg;

$database = "inquiries";
$conn = Pg::connectdb("dbname = $database");

$query = "select * from sales where acctid = 'dave'";
$result = $conn->exec("$query");
# should check to see if status is ok if not fail it
$status = $conn->status;
$errorMessage = $conn->errorMessage;
$cmdStatus = $result->cmdStatus;

$result_status = $result->resultStatus;
$ntuples = $result->ntuples;
$nfields = $result->nfields;

All of the data selected is returned in the result object.
At this point you need to iterate through it to get the data:

Here's an example:

for ( my $tuple = 0 ; $tuple < $result->ntuples ; $tuple++ )
{
for ( my $field = 0 ; $field < $result->nfields ; $field++ )
{
printf( "%d: %s = %s\n", $tuple, $result->fname( $field ),
$result->getvalue( $tuple, $field ) );
}
}

-------------
Diab Jerius Harvard-Smithsonian Center for Astrophysics
60 Garden St, MS 70, Cambridge MA 02138 USA
djerius@cfa.harvard.edu vox: 617 496 7575 fax: 617 495 7356

#8Rob den Boer
rdboer@hrs-rotterdam.nl
In reply to: David Zampese (#1)
RE: [GENERAL] pg_result

Dave,

$result = pg_Exec($conn, "$query");
if (!$result);
echo "An error occured inserting information into our
database.\n";
exit;
else;
pg_close ($conn);
endif;
$rows = pg_result($result,0,"row1");

(Assuming you're using php3)

I think something like this is what you're looking for:

$conn = pg_Connect("localhost", "5432", "", "", "efakt");
if (!$conn) {
echo "Cannot connect to PostgreSQL database.\n";
exit;
}

$result = pg_Exec($conn, "set datestyle='ISO';
select * from invoices
where seqid = $invid");
if (!$result) {
echo "Faktuur niet gevonden! ($resinv $invid)\n";
exit;
}

$num = pg_NumRows($result);
$i = 0;

while ($i < $num) {
echo pg_Result($result, $i, "invoiceno");
$i++;
}

pg_FreeResult($result);
pg_Close($conn);

Rob den Boer