Jump to content

TypeError: mysql.query is not a function


Recommended Posts

Posted

Why am I get this error?

C:\RAGEMP\server-files\packages\RPG\events.js:20: TypeError: mysql.query is not a function
    mysql.query('INSERT INTO players (scID, posX, posY, posZ) VALUES ('+scID+', '+posX+', '+posY+', '+posZ+'', [], function(e, r) {


My events.js:

var mysql = require('mysql');

mp.events.add('playerJoin', (player) => {
    console.log(`[SERVIDOR]: ${player.name} [${player.id}] entrou no servidor.`);
    mp.players.broadcast(`!{${corJogador}} ${player.name} !{${corInfo}} entrou no servidor.`);
    scID = player.rgscId
    posX = 100
    posY = 100
    posZ = 100
    mysql.query('INSERT INTO players (scID, posX, posY, posZ) VALUES ('+scID+', '+posX+', '+posY+', '+posZ+'', [], function(e, r) {
        if(e) {
        console.log('ERROR');
        throw e;
        }
        else {
        console.log('ADDED');
        }
        });
});

mp.events.add("playerChat", (text) => {
    if (text === "teste") {
        player.outputChatBox(`Escreveste 'teste' no chat.`);
    }
});


My connection.js (where I make the connection (everything works perfectly)):

ar mysql = require('mysql');

var mysql = mysql.createConnection({
  host:'127.0.0.1',// host of server
  user:'root',// MySQL user
  password:'PASSWORD',// MySQL password
  database: "rpg"
});

mysql.connect(function(e) {
  if(e) {
    console.log("Error connecting to the database with error "+e);
  }
  else {
    console.log('Database connected!')
  }
  });

mysql.query("CREATE TABLE players (id int NOT NULL PRIMARY KEY, scID int NOT NULL UNIQUE, posX int NOT NULL, posY int NOT NULL, posZ int NOT NULL)", [], function(e, r) {
  if(e) {
  console.log('There was an error while creating [players]');
  throw e;
  }
  else {
  console.log('[players] has been created');
  }
  });


My index.js:

//init Commands file
require('./commands.js')

//init Events file
require('./events.js')

require('./veiculos.js')

require('./armas.js')

require('./mortes.js')

require('./animacoes.js')

require('./connection.js')

var mysql = require('mysql');

 

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...