pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Trouble with SQL statement using variable
5+ messages / 3 participants
[nested] [flat]

* Trouble with SQL statement using variable
@ 2002-01-29 18:34  Jeff Self <jself@nngov.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Jeff Self @ 2002-01-29 18:34 UTC (permalink / raw)
  To: pgsql-php

I'm having trouble getting an SQL statement to use a variable. Here's
the statement:

		$sql = "SELECT emp_fname FROM employee WHERE username = '$username'";
		$result = pg_exec($conn,$sql);
			if (!$result) {
				exit;
			}
I get the following warning from this:

Warning: Supplied argument is not a valid PostgreSQL link resource in
/var/www/personnel/include/functions.inc on line 25

Is there another way to use a variable in an SQL statement. This format
works with MySQL.

-- 
Jeff Self
Information Technology Analyst
Department of Personnel
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930




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

* Re: Trouble with SQL statement using variable
@ 2002-01-29 19:09  Frank Bax <fbax@sympatico.ca>
  parent: Jeff Self <jself@nngov.com>
  1 sibling, 2 replies; 5+ messages in thread

From: Frank Bax @ 2002-01-29 19:09 UTC (permalink / raw)
  To: Jeff Self <jself@nngov.com>; +Cc: pgsql-php

I believe this is a problem with $conn, not your sql syntax.  How is $conn
defined?  Is it passed as an argument to the function containing this code,
or defined as a global?  Are you using pg_pconnect or pg_connect()?

At 01:34 PM 1/29/02 -0500, Jeff Self wrote:
>I'm having trouble getting an SQL statement to use a variable. Here's
>the statement:
>
>		$sql = "SELECT emp_fname FROM employee WHERE username = '$username'";
>		$result = pg_exec($conn,$sql);
>			if (!$result) {
>				exit;
>			}
>I get the following warning from this:
>
>Warning: Supplied argument is not a valid PostgreSQL link resource in
>/var/www/personnel/include/functions.inc on line 25
>
>Is there another way to use a variable in an SQL statement. This format
>works with MySQL.
>
>-- 
>Jeff Self
>Information Technology Analyst
>Department of Personnel
>City of Newport News
>2400 Washington Ave.
>Newport News, VA 23607
>757-926-6930
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
>http://www.postgresql.org/users-lounge/docs/faq.html
>



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

* Re: Trouble with SQL statement using variable
@ 2002-01-29 19:19  Jeff Self <jself@nngov.com>
  parent: Frank Bax <fbax@sympatico.ca>
  1 sibling, 0 replies; 5+ messages in thread

From: Jeff Self @ 2002-01-29 19:19 UTC (permalink / raw)
  To: Frank Bax <fbax@sympatico.ca>; +Cc: pgsql-php

On Tue, 2002-01-29 at 14:09, Frank Bax wrote:
> I believe this is a problem with $conn, not your sql syntax.  How is $conn
> defined?  Is it passed as an argument to the function containing this code,
> or defined as a global?  Are you using pg_pconnect or pg_connect()?
$conn is defined as a global in a file called database.inc which is
here:

<?php
//
// database.inc
//
// Database Information

	$dbname = "personnel";
	$dbuser = "webuser";

	$conn = pg_pconnect("dbname=$dbname user=$dbuser");
	if (!$conn) {
		echo "Could not connect to database.";
		exit;
	}
?>

As you can see, I'm using pg_pconnect.


> 
> At 01:34 PM 1/29/02 -0500, Jeff Self wrote:
> >I'm having trouble getting an SQL statement to use a variable. Here's
> >the statement:
> >
> >		$sql = "SELECT emp_fname FROM employee WHERE username = '$username'";
> >		$result = pg_exec($conn,$sql);
> >			if (!$result) {
> >				exit;
> >			}
> >I get the following warning from this:
> >
> >Warning: Supplied argument is not a valid PostgreSQL link resource in
> >/var/www/personnel/include/functions.inc on line 25
> >
> >Is there another way to use a variable in an SQL statement. This format
> >works with MySQL.
> >
> >-- 
> >Jeff Self
> >Information Technology Analyst
> >Department of Personnel
> >City of Newport News
> >2400 Washington Ave.
> >Newport News, VA 23607
> >757-926-6930
> >
> >
> >---------------------------(end of broadcast)---------------------------
> >TIP 5: Have you checked our extensive FAQ?
> >
> >http://www.postgresql.org/users-lounge/docs/faq.html
> >
-- 
Jeff Self
Information Technology Analyst
Department of Personnel
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930




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

* Re: Trouble with SQL statement using variable
@ 2002-01-29 20:01  Jeff Self <jself@nngov.com>
  parent: Frank Bax <fbax@sympatico.ca>
  1 sibling, 0 replies; 5+ messages in thread

From: Jeff Self @ 2002-01-29 20:01 UTC (permalink / raw)
  To: Frank Bax <fbax@sympatico.ca>; +Cc: pgsql-php

I solved it. I had to pass the $conn when calling the function.

On Tue, 2002-01-29 at 14:09, Frank Bax wrote:
> I believe this is a problem with $conn, not your sql syntax.  How is $conn
> defined?  Is it passed as an argument to the function containing this code,
> or defined as a global?  Are you using pg_pconnect or pg_connect()?
> 
> At 01:34 PM 1/29/02 -0500, Jeff Self wrote:
> >I'm having trouble getting an SQL statement to use a variable. Here's
> >the statement:
> >
> >		$sql = "SELECT emp_fname FROM employee WHERE username = '$username'";
> >		$result = pg_exec($conn,$sql);
> >			if (!$result) {
> >				exit;
> >			}
> >I get the following warning from this:
> >
> >Warning: Supplied argument is not a valid PostgreSQL link resource in
> >/var/www/personnel/include/functions.inc on line 25
> >
> >Is there another way to use a variable in an SQL statement. This format
> >works with MySQL.
> >
> >-- 
> >Jeff Self
> >Information Technology Analyst
> >Department of Personnel
> >City of Newport News
> >2400 Washington Ave.
> >Newport News, VA 23607
> >757-926-6930
> >
> >
> >---------------------------(end of broadcast)---------------------------
> >TIP 5: Have you checked our extensive FAQ?
> >
> >http://www.postgresql.org/users-lounge/docs/faq.html
> >
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
-- 
Jeff Self
Information Technology Analyst
Department of Personnel
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930




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

* Re: Trouble with SQL statement using variable
@ 2002-01-29 20:02  jeff fitzmyers <fitz22@earthlink.net>
  parent: Jeff Self <jself@nngov.com>
  1 sibling, 0 replies; 5+ messages in thread

From: jeff fitzmyers @ 2002-01-29 20:02 UTC (permalink / raw)
  To: pgsql-php

Have you tried:
	echo "CONN: $conn<br>";
	echo "SQL: $sql<br>";
to see what is being passed to postgres?
Jeff

On Tuesday, January 29, 2002, at 10:34 AM, Jeff Self wrote:

> I'm having trouble getting an SQL statement to use a variable. Here's
> the statement:
>
> 		$sql = "SELECT emp_fname FROM employee WHERE username = '$username'";
> 		$result = pg_exec($conn,$sql);
> 			if (!$result) {
> 				exit;
> 			}
> I get the following warning from this:
>
> Warning: Supplied argument is not a valid PostgreSQL link resource in
> /var/www/personnel/include/functions.inc on line 25
>
> Is there another way to use a variable in an SQL statement. This format
> works with MySQL.
>
> --
> Jeff Self
> Information Technology Analyst
> Department of Personnel
> City of Newport News
> 2400 Washington Ave.
> Newport News, VA 23607
> 757-926-6930
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>




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


end of thread, other threads:[~2002-01-29 20:02 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-29 18:34 Trouble with SQL statement using variable Jeff Self <jself@nngov.com>
2002-01-29 19:09 ` Frank Bax <fbax@sympatico.ca>
2002-01-29 19:19   ` Jeff Self <jself@nngov.com>
2002-01-29 20:01   ` Jeff Self <jself@nngov.com>
2002-01-29 20:02 ` jeff fitzmyers <fitz22@earthlink.net>

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