S
S
Space2014-03-20 16:36:18
JavaScript
Space, 2014-03-20 16:36:18

Why is not added to mysql node.js?

Hello. The task is to add data to the database.

mysql = require('mysql')
  connection = mysql.createConnection({
    host     : 'localhost',
    user     : 'xxx',
    password : 'ccc',
    database : 'vvv'
  });
var post  = {text: 'abc' };
    var query = connection.query('INSERT INTO texter VALUES ?', post, function(err, result) {
    });
console.log(query.sql);

The console outputs INSERT INTO texter VALUES `text` = 'abc'The table consists of one text field, but nothing is added, why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2014-03-20
@ruslite

May be because connection.connect();
UPDATE is omitted
Full example from documentation:

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'me',
  password : 'secret'
});

connection.connect();

connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
  if (err) throw err;

  console.log('The solution is: ', rows[0].solution);
});

connection.end();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question