nodejs mysql

功能:一次插入多條數據;mysql

參考:https://www.jianshu.com/p/62a9d2340c56git

github:https://github.com/mysqljs/mysqlgithub

代碼sql

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();
相關文章
相關標籤/搜索