I'm wondering if this stored procedure is correct. I'm trying to call this procedure in php which will put two bound varchar parameters through to the stored procedure. However I'm getting the error:
invalid parameter number :: name
where 'name' is one of the parameters I'm using.
What is the problem with my code?
CREATE OR REPLACE FUNCTION treasurehunt.huntlogin(character varying, character varying)
RETURNS bigint AS
$BODY$SELECT COUNT(*) FROM TreasureHunt.Player
WHERE name=$1 AND password=$2$BODY$
LANGUAGE sql VOLATILE
COST 100;
ALTER FUNCTION treasurehunt.huntlogin(character varying, character varying)
OWNER TO abro9592;
Here is the php
function checkLogin($name,$pass) {
// STUDENT TODO:
// Replace line below with code to validate details from the database
$db = connect();
try {
$stmt = $db->prepare('SELECT COUNT(*) FROM treasurehunt.huntlogin (:user,:pass)');
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->bindValue(':pass', $pass, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchColumn();
$stmt->closeCursor();
} catch (PDOException $e) {
print "Error checking login: " . $e->getMessage();
return FALSE;
}
return ($result==1);
}