Answer the question
In order to leave comments, you need to log in
How to handle mysql connection error?
How to do this if the connection fails, no error occurred? (new to this)
const mysql = require("mysql2");
const pool = mysql.createConnection({
host: "localhost",
user: "root",
database: "name",
password: "password"
});
let reg = `INSERT INTO users(name) VALUES('name')`;
pool.query(reg, function(err, results) {
if(err) console.log(err);
});
Answer the question
In order to leave comments, you need to log in
pool.connect(function(err){
if (err) {
return console.error("Ошибка: " + err.message);
}
else{
console.log("Подключение к серверу MySQL успешно установлено");
// здесь можно делать запросы
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question