0

我想知道这个存储过程是否正确。我正在尝试在 php 中调用此过程,这会将两个绑定的 varchar 参数传递给存储过程。但是我收到了错误:

无效的参数号 :: 名称

其中“名称”是我正在使用的参数之一。

我的代码有什么问题?

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;

这是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);

}
4

0 回答 0