pg_query won't execute

From: "Dale Schmitz" <dschmitz4(at)cox(dot)net>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: pg_query won't execute
Date: 2018-03-04 20:10:27
Message-ID: 000301d3b3f4$da473c10$8ed5b430$@cox.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2018-03-04 20:39:36 Re: pg_query won't execute
Previous Message David Rowley 2018-03-03 10:20:19 Re: STATISTICS retained in CREATE TABLE ... LIKE (INCLUDING ALL)?