Approach to multiple MySQL queries with Node.js

前端 未结 4 1635
南笙
南笙 2020-12-01 03:19

I\'m a newbie both on event/callback style programming and NodeJS. I\'m trying to implement a little http server which serves ddbb data using node-mysql module.

My p

4条回答
  •  萌比男神i
    2020-12-01 03:45

    Another solution is to concatenate all statements, ending each with a semicolon. For example, to select from multiple tables you could use this query:

    var sql = 'select * from user; select * from admin;'

    Then, you can use only one connection to execute the multiple statements:

    var connection = mysql.createConnection({multipleStatements: true}) connection.query(sql)

    Note: Multiple statements is disabled by default to prevent SQL injection. Be sure to properly escape all values (see docs).

提交回复
热议问题