pg_query won't execute - Mailing list pgsql-novice

From Dale Schmitz
Subject pg_query won't execute
Date
Msg-id 000301d3b3f4$da473c10$8ed5b430$@cox.net
Whole thread Raw
Responses Re: pg_query won't execute  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice

I’m learning PHP for PostgreSQL and have come across something I can’t figure out.

 

The statement “SELECT COUNT(*) FROM users WHERE username = ‘john’ works just fine in the pgAdmin query tool, but not like this:

 

$sql = “SELECT COUNT(*) FROM users WHERE username = $username”;

If ($result = pg_query($dbconn,$sql)) {

                …process statements…

} else {

                echo “Could not execute $sql”;

}

 

$dbconn is a valid resource (I’ve changed up the $sql statement to test, and it works just fine), so no problem there.  The problem is incurred when I attempt to COUNT something.

 

Is there a different method I should be using for returning a count?

 

Thanks

Dale

pgsql-novice by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: "invalid input syntax for integer" for number with exponent
Next
From: Tom Lane
Date:
Subject: Re: pg_query won't execute