Dale Schmitz
2018-03-04 20:10:27 UTC
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
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