NodeJS如何显示存储过程中的值

时间:2019-02-14 16:23:32

标签: mysql node.js

我有一个存储过程,具有2 ins和2 outs和一个nodejs应用程序,该应用程序对该过程进行调用以验证密码是否满足要求。一切都能正确执行(数据库连接,调用过程),但是我不知道如何获取存储过程的输出值

// SQL过程

CREATE DEFINER=`root`@`localhost` PROCEDURE `password_validation`(IN user_password varchar(255), IN password_confirmation varchar(255), OUT valid bool, OUT description varchar(255))
BEGIN
IF (user_password != password_confirmation) then
    set Valid = false;
    set Description = 'Passwords do not match';
ELSEIF (user_password RLIKE '[0-9]' And LENGTH(user_password) >= 8 ) then
    set Valid = true;
    set Description = 'Valid Password';
ELSE
    set Valid = false;
    set Description = 'Password must be at least 8 characters, have at least 1 number';
END IF;
END

/// Nodejs

app.post('/signup', urlencodedParser, function(req,res){
    let sql = "Call password_validation(?, ?, @valid, @description)"
    db.query(sql, [req.body.password, req.body.confirm_password], function(err, results){
        if (err){
            console.log(err);
        } else{
              //Display Decription/Valid
        }  
    })
});

0 个答案:

没有答案