Is there a driver for mysql on nodejs that supports stored procedures?

后端 未结 5 1676
孤独总比滥情好
孤独总比滥情好 2020-12-09 19:40

I am looking for a mySQL driver for nodejs that supports stored procedures. http://nodejsdb.org/db-mysql/ that I have been using gives the error

PROCEDURE can\'t r

5条回答
  •  执念已碎
    2020-12-09 20:16

    node-mysql driver work with stored procedure and its very simple just call your stored procedure with parameter.

    CREATE PROCEDURE GetAllStudent(id int)
    BEGIN
    SELECT * FROM student where userid = id ;
    END;
    

    and in node just call

    app.get('/sp', function (req, res, next) {
        connection.connect();
        connection.query('CALL GetAllStudent(?)',[req.body.id],function (err, rows, fields) {
            if (err) {
                res.status(400).send(err);
            }
            res.status(200).send(rows);
        });
    
        connection.end();
    });
    

    this way no need to worry of sql injection.

    here is good tutorial on nodejs and mysql

提交回复
热议问题