Answer the question
In order to leave comments, you need to log in
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);
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
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 questionAsk a Question
731 491 924 answers to any question