pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Problem with PHP and PostgreSQL
4+ messages / 2 participants
[nested] [flat]

* Problem with PHP and PostgreSQL
@ 2004-02-04 20:20  Seader, Cameron <CSeader@idahopower.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Seader, Cameron @ 2004-02-04 20:20 UTC (permalink / raw)
  To: pgsql-php

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 
for($i = 0; $i < $fieldcounts; $i++)
 { 
 	$fieldtype = pg_fieldtype($query_panels, $i); 
	echo "$fieldtype->name"; 
	if ($i < ($fieldcounts-1)) 
	echo ","; else echo "\n"; 
 } 
//**** Output each row of Data 
while ($myrow = pg_fetch_row($query_panels)) 
	{ 
		for($i = 0; $i < $fieldcounts; $i++) 
		{ 
			$fieldname = pg_fieldname($query_panels, $i); 
			if ($i < ($fieldcounts-1)) echo $myrow[$fieldname] . ", "; 
			else echo $myrow[$fieldname] . "\n"; 
		} 
	}

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 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





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Problem with PHP and PostgreSQL
@ 2004-02-04 21:09  scott.marlowe <scott.marlowe@ihs.com>
  parent: Seader, Cameron <CSeader@idahopower.com>
  0 siblings, 0 replies; 4+ messages in thread

From: scott.marlowe @ 2004-02-04 21:09 UTC (permalink / raw)
  To: Seader, Cameron <CSeader@idahopower.com>; +Cc: pgsql-php

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...




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Problem with PHP and PostgreSQL
@ 2004-02-04 21:17  Seader, Cameron <CSeader@idahopower.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Seader, Cameron @ 2004-02-04 21:17 UTC (permalink / raw)
  To: scott.marlowe <scott.marlowe@ihs.com>; +Cc: pgsql-php

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





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Problem with PHP and PostgreSQL
@ 2004-02-04 21:18  scott.marlowe <scott.marlowe@ihs.com>
  parent: Seader, Cameron <CSeader@idahopower.com>
  0 siblings, 0 replies; 4+ messages in thread

From: scott.marlowe @ 2004-02-04 21:18 UTC (permalink / raw)
  To: Seader, Cameron <CSeader@idahopower.com>; +Cc: pgsql-php

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
> 
> 
> 




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2004-02-04 21:18 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-02-04 20:20 Problem with PHP and PostgreSQL Seader, Cameron <CSeader@idahopower.com>
2004-02-04 21:09 ` scott.marlowe <scott.marlowe@ihs.com>
2004-02-04 21:17 Re: Problem with PHP and PostgreSQL Seader, Cameron <CSeader@idahopower.com>
2004-02-04 21:18 ` scott.marlowe <scott.marlowe@ihs.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox