为了安全起见,默认情况下是不允许执行多条查询语句的。要使用多条查询语句的功能,就需要在创建数据库连接的时候打开这一功能:
var connection = ?mysql.createConnection( { multipleStatements: true } ); ?
这一功能打开以后,你就可以像下面的例子一样同时使用多条查询语句:
connection.query(‘select column1; select column2; select column3;‘, function(err, result){ ???if(err){ ?????throw err; ???}else{ ?????console.log(result[0]); ??????// Column1 as a result ?????console.log(result[1]); ??????// Column2 as a result ?????console.log(result[2]); ??????// Column3 as a result ???} ?}); ?
即:
var connParam = { ?????host ????: ‘localhost‘, ?????user ????: ‘root ???‘, ?????password : ‘root‘, ?????port ??????: ‘3306‘, ???????????????database : ‘testdb‘, ?????multipleStatements: true};