我正在使用数据库Stored Procedures
中的登录身份验证。MySQL
下面是我写的代码,但它不起作用。让我知道,有什么问题。
我有以下问题
- 如何检查,
CURSOR
是empty
或null
- 有什么办法,我们写程序。
我在做什么..
取两个
input
参数和两个参数ouput
。检查用户或密码是否无效,将这些值存储在 OUT 参数中
SELECT 'Invalid username and password', 'null' INTO oMessage, oUserID;
如果用户和密码有效,但 列
isActive
是0
SELECT 'Inactive account', 'null' INTO oMessage, oUserID;
如果成功,
SELECT 'Success', v_UserID INTO oMessage, oUserID;
SQL 代码
DELIMITER $$
USE `acl`$$
CREATE
DEFINER = `FreeUser`@`localhost`
PROCEDURE `acl`.`checkAuthenticationTwo`(
IN iUsername VARCHAR(50),
IN iPassword VARCHAR(50),
OUT oMessage VARCHAR(50),
OUT oUserID INT
)
BEGIN
DECLARE v_isActive INT;
DECLARE v_UserID INT;
DECLARE v_count INT;
DECLARE cur1 CURSOR FOR SELECT UserID, IsActive FROM m_users WHERE (LoginName = TRIM(iUsername) OR Email = TRIM(iUsername)) AND `Password` = iPassword;
OPEN cur1;
SET v_count = (SELECT FOUND_ROWS());
IF (v_count > 0)
FETCH cur1 INTO v_UserID, v_isActive;
IF (v_isActive = 0) THEN
SELECT 'Inactive account', 'null' INTO oMessage, oUserID;
ELSE
SELECT 'Success', v_UserID INTO oMessage, oUserID;
END IF;
ELSE
SELECT 'Invalid username and password', 'null' INTO oMessage, oUserID;
END IF;
END$$
DELIMITER ;