首页 > 技术文章 > nodejs mysql

wang-jing 2019-07-23 20:14 原文

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

参考: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();

 

推荐阅读