0

I'd like to insert these data name, title, body, timestamp, img_url to a new column in MySQL. How do I achieve that.

  static post(name) {
    return db.execute('INSERT INTO tablename (name) VALUES (?)', [name]);
  }
Clinton
  • 435
  • 1
  • 4
  • 13
  • Does this answer your question? [Insert multiple columns and rows into SQL Server with node js](https://stackoverflow.com/questions/50840196/insert-multiple-columns-and-rows-into-sql-server-with-node-js) – Darth Jan 20 '21 at 14:38

1 Answers1

1
const mysqlConnection = require('mysql');
const conn = mysql.createConnection({...});

var query = "INSERT INTO your_table (name, email, n) VALUES ?";
var values = [
    ['test1', 'test@gmail.com', 1],
    ['test2', 'test1@gmail.com', 2],
];
conn.query(sql, [values], function(err) {
    if (err) throw err;
    conn.end();
});
Levon Babayan
  • 266
  • 2
  • 18
  • 1
    Thank you. But it is very difficult to write a insert query like this. As I have more than 20 values (fields).. – raj Jun 01 '22 at 09:43