nodejs mysql

功能:一次插入多条数据;

参考:https://www.jianshu.com/p/62a9d2340c56

github:https://github.com/mysqljs/mysql

代码

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : '127.0.0.1',
  user     : 'root',
  password : 'root',
  database : 'kg-hanyu'
});

connection.connect();

// connection.query('SELECT * from word', function (error, results, fields) {
//   if (error) throw error;
//   console.log('The solution is: ', results);
// });

var post = [[4, '', 3, 0],[5, '', 3, 0]];
connection.query('INSERT INTO word VALUES ?', [post], function (error, results, fields) {
  if (error) throw error;
});

connection.end();

 

posted on 2019-07-23 20:14  j.w  阅读(199)  评论(0编辑  收藏  举报