我正在使用存储过程来登录用户,我需要返回玩家ID。我测试时提供的名称和密码是正确的,结果返回1但是playerID保持为NULL
`player_login` (
username TEXT CHARACTER SET utf8,
txtPassword TEXT CHARACTER SET utf8,
OUT playerID INTEGER,
OUT result INTEGER
)
BEGIN
DECLARE password TEXT DEFAULT player_hash_password(txtPassword);
DECLARE num INTEGER DEFAULT 0;
SELECT PlayerID INTO playerID
FROM players
WHERE (LOWER(players.PlayerName)=LOWER(username) OR LOWER(players.PlayerEmail)=LOWER(username))
AND players.PlayerPassword = password
LIMIT 1;
...
为什么未将PlayerID选入playerID? PlayerID是一个非空的自动增量整数。
答案 0 :(得分:2)
您的参数与列名称匹配,这是MySQL存储过程的长期问题。为参数使用前缀,例如:
`player_login` (
p_username TEXT CHARACTER SET utf8,
p_txtPassword TEXT CHARACTER SET utf8,
OUT p_playerID INTEGER,
OUT p_result INTEGER
)
BEGIN
DECLARE p_password TEXT DEFAULT player_hash_password(p_txtPassword);
DECLARE num INTEGER DEFAULT 0;
SELECT p_PlayerID = playerID
FROM players p
WHERE (LOWER(p.PlayerName)=LOWER(p_username) OR LOWER(p.PlayerEmail)=LOWER(p_username))
AND p.PlayerPassword = p_password
LIMIT 1;
.