D
D
Dvorak2016-08-16 11:33:13
MySQL
Dvorak, 2016-08-16 11:33:13

Why query error in MySQL?

Hello, I'm trying to master the MySQL + Node. For some reason, when executing this code:

const mysql = require('mysql');

const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: 'password'
});

connection.connect();
const person = 'Ginger Baker';
      
const query = connection.query("INSERT INTO ?? SET ?? = ?", ['artist', 'name', 'person'], (err, rows) => {
  if (err) {
    console.log('Ошибка запроса');
    console.log(err);
  } else {
    console.log(rows);
  };
});
connection.end();

I get this:
4f64170c002c430199316148f10c9291.png
At the same time, opening and closing the connection occur without errors, I checked. What is the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pretor DH, 2016-08-16
@allishappy

No database selected:

const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: 'password',
  database: 'my_db'                      <===============
});

Smoke the article ...

A
Alexander Aksentiev, 2016-08-16
@Sanasol

second line, are you kidding me?
841c167c7b6cde7717ab494a98be.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question