7inage Posted August 5, 2019 Posted August 5, 2019 Good day, friends, help solve the problem. The fact is that MYSQL is connected, and the query is not executed at all. Does not write anything to the console. Help Sorry for my English var mysql = require('mysql'); let mysqlc = mysql.createConnection({ host: '...', user: '...', password: '...', database: '...' }); mysqlc.connect(function(e) { console.log('Connecting ... '); if(e) { console.log("Error connecting to the database with error "+e); } else { console.log('Database connected!') } }); mp.events.add("CheckedLogin", (UserName, Password) => { console.log('Call ... '); mysqlc.query("SELECT * FROM `Player` WHERE `UserName`=", [UserName], function(e, r) { console.log('Load ... '); if(e) { console.log('Error on connection ... '); throw e; } else { console.log('Password is '); } }); mysqlc.end(); }); The event call works, but after the query in the database, nothing works ... Thank!
LeonMrBonnie Posted August 5, 2019 Posted August 5, 2019 Remove the line : mysqlc.end(); This closes the mysql connection completely, which you probably don't want.
7inage Posted August 5, 2019 Author Posted August 5, 2019 10 минут назад, LeonMrBonnie сказал: Remove the line : mysqlc.end(); This closes the mysql connection completely, which you probably don't want. Nothing has changed, the request is still not executed.
LeonMrBonnie Posted August 5, 2019 Posted August 5, 2019 If it really does not write anything to the console try logging something at the very top of the file, to see if it is even loaded at all. If not, show us where you require that file.
7inage Posted August 5, 2019 Author Posted August 5, 2019 1 час назад, LeonMrBonnie сказал: If it really does not write anything to the console try logging something at the very top of the file, to see if it is even loaded at all. If not, show us where you require that file. Sorry for the error, the only thing he writes to the console is: console.log ('Call ...'); At the very beginning of the event, and I put the message in the console after mysqlc.query, he also writes, but everything in mysqlc.query cohd something passes by.
LeonMrBonnie Posted August 6, 2019 Posted August 6, 2019 Try this: (You forgot the ? placeholder at the end) "SELECT * FROM `Player` WHERE `UserName`=?"
7inage Posted August 6, 2019 Author Posted August 6, 2019 (edited) 3 часа назад, LeonMrBonnie сказал: Try this: (You forgot the ? placeholder at the end) "SELECT * FROM `Player` WHERE `UserName`=?" Everything is just as bad, the fact is that mysql does not even give out information about the connection, that is, it does not write errors, not that it successfully connects to the database and checks the call at the beginning of the connection, either ... Edited August 6, 2019 by 7inage
LeonMrBonnie Posted August 6, 2019 Posted August 6, 2019 Try wrapping your whole code into a try catch like this: try { var mysql = require('mysql'); let mysqlc = mysql.createConnection({ host: '...', user: '...', password: '...', database: '...' }); mysqlc.connect(function(e) { console.log('Connecting ... '); if(e) { console.log("Error connecting to the database with error "+e); } else { console.log('Database connected!') } }); mp.events.add("CheckedLogin", (UserName, Password) => { console.log('Call ... '); mysqlc.query("SELECT * FROM `Player` WHERE `UserName`=", [UserName], function(e, r) { console.log('Load ... '); if(e) { console.log('Error on connection ... '); throw e; } else { console.log('Password is '); } }); mysqlc.end(); }); } catch(e) { console.log(e); }
7inage Posted August 6, 2019 Author Posted August 6, 2019 8 минут назад, LeonMrBonnie сказал: Try wrapping your whole code into a try catch like this: try { var mysql = require('mysql'); let mysqlc = mysql.createConnection({ host: '...', user: '...', password: '...', database: '...' }); mysqlc.connect(function(e) { console.log('Connecting ... '); if(e) { console.log("Error connecting to the database with error "+e); } else { console.log('Database connected!') } }); mp.events.add("CheckedLogin", (UserName, Password) => { console.log('Call ... '); mysqlc.query("SELECT * FROM `Player` WHERE `UserName`=", [UserName], function(e, r) { console.log('Load ... '); if(e) { console.log('Error on connection ... '); throw e; } else { console.log('Password is '); } }); mysqlc.end(); }); } catch(e) { console.log(e); } Nothing has changed, but when I did not enter the data for the connection, I got errors and console.log ('Connecting ...') was called, but when I put my data for the connection, everything returned to its place
7inage Posted August 6, 2019 Author Posted August 6, 2019 @LeonMrBonnie Thank you for trying to help, I decided the problem was not in the code, but in the base to which I was connecting ... It is in the KNOB parameter.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now