Answer the question
In order to leave comments, you need to log in
Why is mysql2 not working?
Why is mysql2 not working?
const TelegramBot = require('node-telegram-bot-api');
const mysql = require('mysql2');
const token = "";
const connection = mysql.createConnection({
host: '65.21.149.173',
user: 'admin_samp',
password: 'Asn123As123',
database: 'admin_samp'
});
const bot = new TelegramBot(token, {polling: true});
bot.on('message', (msg) => {
const chatId = msg.from.id;
const text = msg.text;
connection.query("SELECT * FROM `users` WHERE chatId = ?",[chatId], function(err,results) {
if(results == 0){
connection.query("INSERT INTO `users` SET chatId = ?, username = ?, login = ?, lencm = 0", [chatId, msg.from.first_name + ' ' + msg.from.last_name, msg.from.username]);
console.log("New user " + msg.from.first_name + ' ' + msg.from.last_name);
connection.commit();
} else{
console.log("m:", text);
}
});
});
Answer the question
In order to leave comments, you need to log in
The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.
Instead of a separate connection, it is best to create a pool, and pull separate requests from it. Then the mysql2 module will pull a connection from the pool for reuse or create a new one if there are no free old ones, or they fell off by timeout. A very handy thing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question