Piesel Posted June 11, 2019 Posted June 11, 2019 Hello! Mysql dosen't work on my server, i don't have any logs in the console from mysql connection. Code; var mysql = require('mysql'); var bcrypt = require('bcrypt-nodejs'); var conn = mysql.createConnection({ host:'replaced', user:'replaced', password:'replaced', database:'replaced' }); conn.connect(function (err) { console.log('Got connected'); });
Doom Posted June 11, 2019 Posted June 11, 2019 Well try to log the error so we can see whats wrong...
Piesel Posted June 11, 2019 Author Posted June 11, 2019 No error in the console, I do not know what's going on.
custom Posted June 11, 2019 Posted June 11, 2019 conn.connect(function(err) { if (err) console.log (err); else console.log("Successful connected to DataBase!"); }); so you will get error in console
Piesel Posted June 11, 2019 Author Posted June 11, 2019 No error is displayed nor does it show that the database has been connected
robearded Posted June 11, 2019 Posted June 11, 2019 then it means that you didn't called your mysql script anywhere in your index.js
Piesel Posted June 11, 2019 Author Posted June 11, 2019 Called. require('./main.js'); require('./main_s.js'); - there is a mysql.
custom Posted June 11, 2019 Posted June 11, 2019 Dude we cant read your code from here. People can help you only if you share with us all your code line associated with your problem.
Piesel Posted June 11, 2019 Author Posted June 11, 2019 (edited) Everything from this folder. And yes, I have a mysql module index.js require('./main.js'); require('./main_s.js'); main.js mp.events.addCommand("v", (player) => { player.outputChatBox('Dostępne komendy związane z samochodami prywatnymi'); player.outputChatBox('/vspawn [id]'); player.outputChatBox('/vlista'); player.outputChatBox('/vudostepnij [id_gracza] [id_pojazdu]'); player.outputChatBox('/vprzypisz [id pojazdu] [id grupy]'); player.outputChatBox('/vulepszenia [id_pojazdu]'); }); mp.events.addCommand("vlista", (player) => { mp.events.call('sprawdzPojazd', player); console.log(`dziala`); }); mp.events.add('wypiszPojazdy', (player) => { let pojazdy = player.getVariable(`pojazd_gracz`); let id = player.getVariable(`id_pojazdow`); player.outputChatBox(`Twoje pojazdy:`); player.outputChatBox(`${id} ${pojazdy}`); }); main_s.js var mysql = require('mysql'); var conn = mysql.createConnection({ host:'re',// host of server user:'re',// MySQL user password:'re',// MySQL password database:'re'// MySQL database }); conn.connect(function(err) { if (err) console.log (err); else console.log("Successful connected to DataBase!"); }); mp.events.add('sprawdzPojazd', (player) => { console.log(`wykonany event`) conn.query("SELECT * from `rp_vehicles` WHERE `login`=", [player], function(e, r) { if(e) { console.log('Error on connection ... '); throw e; } else { console.log(`wykonany event2`); player.setVariable('pojazd_gracz', r[0].model); player.setVariable('id_pojazdow', r[0].id); mp.events.call('wypiszPojazdy', player); } }); }); Edited June 11, 2019 by Piesel
SupperCraft5000 Posted August 14, 2019 Posted August 14, 2019 You must have mysql with "npm i mysql" installed My constants.js // database mysqlHost: "replaceThis", mysqlUser: "replaceThis", mysqlPass: "replaceThis", mysqlDatabase: "replaceThis", // messages infoPre: "\x1b[92m[replaceThis]\x1b[0m", initErrorPre: "\x1b[91m[replaceThis Init Error] \x1b[0m", }; And my database.js const mysql = require("mysql"); const constants = require("./constants"); module.exports = { Pool: null, Connect: function(callback) { this.Pool = mysql.createPool({ host: constants.mysqlHost, user: constants.mysqlUser, password: constants.mysqlPass, database: constants.mysqlDatabase }); this.Pool.getConnection((err, conn) => { if (!err) { console.log(`${constants.infoPre} Connected to database.`); callback(); } else { console.log(constants.initErrorPre + err.message); } conn.release(); }); } };
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