Problem with PHP and PostgreSQL

Problem with PHP and PostgreSQL

am 04.02.2004 21:20:04 von CSeader

I am having trouble with the following loops and such and accessing Postgre=
SQL database.
The errors i get are:

Warning: pg_num_fields(): supplied argument is not a valid PostgreSQL resul=
t resource in /var/www/html/PMS/csv_export.php on line 108

Warning: pg_fetch_row(): supplied argument is not a valid PostgreSQL result=
resource in /var/www/html/PMS/csv_export.php on line 118

Here is my Code Below:
//**** SQL Query
$query_panels =3D sprintf("SELECT * FROM %s WHERE utctime AT TIME ZONE 'MST=
' BETWEEN '%s' AND '%s' ORDER BY utctime %s", $MM_param1__panels,$MM_param2=
__panels,$MM_param3__panels,$MM_param4__panels);
//**** Count Fields=20
$fieldcounts =3D pg_num_fields($query_panels);=20
//**** List fields as first Row=20
for($i =3D 0; $i < $fieldcounts; $i++)
{=20
$fieldtype =3D pg_fieldtype($query_panels, $i);=20
echo "$fieldtype->name";=20
if ($i < ($fieldcounts-1))=20
echo ","; else echo "\n";=20
}=20
//**** Output each row of Data=20
while ($myrow =3D pg_fetch_row($query_panels))=20
{=20
for($i =3D 0; $i < $fieldcounts; $i++)=20
{=20
$fieldname =3D pg_fieldname($query_panels, $i);=20
if ($i < ($fieldcounts-1)) echo $myrow[$fieldname] . ", ";=20
else echo $myrow[$fieldname] . "\n";=20
}=20
}

Why do i get those errors?
Why is it not a valid result resource?
any help would be awsome.
Thanks,

Cameron Seader
mailto:CSeader@Idahopower.com
1.208.388.2582 Office



[INFO] -- Access Manager:
This transmission may contain information that is privileged, confidential =
and/or exempt from disclosure under applicable law. If you are not the int=
ended recipient, you are hereby notified that any disclosure, copying, dist=
ribution, or use of the information contained herein (including any relianc=
e thereon) is STRICTLY PROHIBITED. If you received this transmission in err=
or, please immediately contact the sender and destroy the material in its e=
ntirety, whether in electronic or hard copy format. Thank you. A2



---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Re: Problem with PHP and PostgreSQL

am 04.02.2004 22:09:08 von Scott Marlowe

On Wed, 4 Feb 2004, Seader, Cameron wrote:

> I am having trouble with the following loops and such and accessing PostgreSQL database.
> The errors i get are:
>
> Warning: pg_num_fields(): supplied argument is not a valid PostgreSQL result resource in /var/www/html/PMS/csv_export.php on line 108
>
> Warning: pg_fetch_row(): supplied argument is not a valid PostgreSQL result resource in /var/www/html/PMS/csv_export.php on line 118
>
> Here is my Code Below:
> //**** SQL Query
> $query_panels = sprintf("SELECT * FROM %s WHERE utctime AT TIME ZONE 'MST' BETWEEN '%s' AND '%s' ORDER BY utctime %s", $MM_param1__panels,$MM_param2__panels,$MM_param3__panels,$MM _param4__panels);
> //**** Count Fields
> $fieldcounts = pg_num_fields($query_panels);
> //**** List fields as first Row

You need to connect to the database and execute your query:

$conn = pg_connect("dbname=bigdb host=myserver user=me2");
$query_panels = sprintf("SELECT... ;
$res = pg_query($conn,$query_panels);
$fieldcount = pg_num_fields($res);

etc...


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Re: Problem with PHP and PostgreSQL

am 04.02.2004 22:17:03 von CSeader

i did i just did not include that part of the code. sorry

-----Original Message-----
From: scott.marlowe [mailto:scott.marlowe@ihs.com]
Sent: Wednesday, February 04, 2004 2:09 PM
To: Seader, Cameron
Cc: pgsql-php@postgresql.org
Subject: Re: [PHP] Problem with PHP and PostgreSQL


On Wed, 4 Feb 2004, Seader, Cameron wrote:

> I am having trouble with the following loops and such and accessing Postg=
reSQL database.
> The errors i get are:
>=20
> Warning: pg_num_fields(): supplied argument is not a valid PostgreSQL res=
ult resource in /var/www/html/PMS/csv_export.php on line 108
>=20
> Warning: pg_fetch_row(): supplied argument is not a valid PostgreSQL resu=
lt resource in /var/www/html/PMS/csv_export.php on line 118
>=20
> Here is my Code Below:
> //**** SQL Query
> $query_panels =3D sprintf("SELECT * FROM %s WHERE utctime AT TIME ZONE 'M=
ST' BETWEEN '%s' AND '%s' ORDER BY utctime %s", $MM_param1__panels,$MM_para=
m2__panels,$MM_param3__panels,$MM_param4__panels);
> //**** Count Fields=20
> $fieldcounts =3D pg_num_fields($query_panels);=20
> //**** List fields as first Row=20

You need to connect to the database and execute your query:

$conn =3D pg_connect("dbname=3Dbigdb host=3Dmyserver user=3Dme2");
$query_panels =3D sprintf("SELECT... ;
$res =3D pg_query($conn,$query_panels);
$fieldcount =3D pg_num_fields($res);

etc...




[INFO] -- Access Manager:
This transmission may contain information that is privileged, confidential =
and/or exempt from disclosure under applicable law. If you are not the int=
ended recipient, you are hereby notified that any disclosure, copying, dist=
ribution, or use of the information contained herein (including any relianc=
e thereon) is STRICTLY PROHIBITED. If you received this transmission in err=
or, please immediately contact the sender and destroy the material in its e=
ntirety, whether in electronic or hard copy format. Thank you. A2



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Re: Problem with PHP and PostgreSQL

am 04.02.2004 22:18:08 von Scott Marlowe

But were you pointing at the result handle or the query string when you
ran pg_num_fields?

This won't work:

$conn = pg_connect("dbname=bigdb host=myserver user=me2");
$query_panels = sprintf("SELECT... ;
$res = pg_query($conn,$query_panels);
$fieldcount = pg_num_fields($query_panels); <-- Notice I put the query
there, not the result handle...

On Wed, 4 Feb 2004, Seader, Cameron wrote:

> i did i just did not include that part of the code. sorry
>
> -----Original Message-----
> From: scott.marlowe [mailto:scott.marlowe@ihs.com]
> Sent: Wednesday, February 04, 2004 2:09 PM
> To: Seader, Cameron
> Cc: pgsql-php@postgresql.org
> Subject: Re: [PHP] Problem with PHP and PostgreSQL
>
>
> On Wed, 4 Feb 2004, Seader, Cameron wrote:
>
> > I am having trouble with the following loops and such and accessing PostgreSQL database.
> > The errors i get are:
> >
> > Warning: pg_num_fields(): supplied argument is not a valid PostgreSQL result resource in /var/www/html/PMS/csv_export.php on line 108
> >
> > Warning: pg_fetch_row(): supplied argument is not a valid PostgreSQL result resource in /var/www/html/PMS/csv_export.php on line 118
> >
> > Here is my Code Below:
> > //**** SQL Query
> > $query_panels = sprintf("SELECT * FROM %s WHERE utctime AT TIME ZONE 'MST' BETWEEN '%s' AND '%s' ORDER BY utctime %s", $MM_param1__panels,$MM_param2__panels,$MM_param3__panels,$MM _param4__panels);
> > //**** Count Fields
> > $fieldcounts = pg_num_fields($query_panels);
> > //**** List fields as first Row
>
> You need to connect to the database and execute your query:
>
> $conn = pg_connect("dbname=bigdb host=myserver user=me2");
> $query_panels = sprintf("SELECT... ;
> $res = pg_query($conn,$query_panels);
> $fieldcount = pg_num_fields($res);
>
> etc...
>
>
>
>
> [INFO] -- Access Manager:
> This transmission may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. A2
>
>
>


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html