kavin

nodejs mysql 执行多条sql语句

kavin IIS 2023-02-27 595浏览 0

执行多条查询语句

为了安全起见,默认情况下是不允许执行多条查询语句的。要使用多条查询语句的功能,就需要在创建数据库连接的时候打开这一功能:

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
};

 

继续浏览有关 数据库技术文章/教程 的文章
发表评论