Piesel

Mysql don't connect

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

 

Share this post


Link to post
Share on other sites

Well try to log the error so we can see whats wrong...

Share this post


Link to post
Share on other sites

No error in the console, I do not know what's going on.

Share this post


Link to post
Share on other sites
conn.connect(function(err) {
  if (err) console.log (err);
  else console.log("Successful connected to DataBase!");
});

so you will get error in console

Share this post


Link to post
Share on other sites

No error is displayed nor does it show that the database has been connected

Share this post


Link to post
Share on other sites

then it means that you didn't called your mysql script anywhere in your index.js

Share this post


Link to post
Share on other sites

Called.

 

			
			require('./main.js');				
			require('./main_s.js'); - there is a mysql.			
	

Share this post


Link to post
Share on other sites

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.

Share this post


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

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
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.