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]);
  }
1

1 Answer 1

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

var query = "INSERT INTO your_table (name, email, n) VALUES ?";
var values = [
    ['test1', '[email protected]', 1],
    ['test2', '[email protected]', 2],
];
conn.query(sql, [values], function(err) {
    if (err) throw err;
    conn.end();
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. But it is very difficult to write a insert query like this. As I have more than 20 values (fields)..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.