码迷,mamicode.com
首页 > Web开发 > 详细

nodejs多语句查询

时间:2017-11-27 15:14:24      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:lan   throw   cti   multi   select   csdn   nod   mysq   nodejs   

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

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
};
技术分享图片

nodejs多语句查询

标签:lan   throw   cti   multi   select   csdn   nod   mysq   nodejs   

原文地址:http://www.cnblogs.com/zhaozhou/p/7727068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
分享档案
周排行
mamicode.com排行更多图片
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!