Jump to content

Mysql don't connect


Piesel

Recommended Posts

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'); });

 
Link to comment
Share on other sites

 

 

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 by Piesel
Link to comment
Share on other sites

  • 2 months later...

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();
        });
    }
};

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...