Jump to content

Load Values From Database To Array


Recommended Posts

hey guys,

i'm new to ragemp and javascript.

i use node. how is it possible to use my mysql connection from other files? Like database.js


my code where i want the connection of database:

"use strict"

const datab = require('../Database');

const List = [];

connection.query("SELECT * FROM `table`", function(error, result) {
	if(error) {
		throw error;
	else {
		console.log('Result is '+result[0].uName);

i want to load my whole table to the List

Link to comment
Share on other sites

You can use exports. 

/* File: database.js */
var mysql = require('mysql');

const connection = mysql.createConnection({
    host: "localhost",
    user: "root",
    database: 'brv_ragemp',
    password: ""
    if (err) throw err;

module.exports.connection = connection;

Other file

/* File: index.js */
var db = require ("./database");

db.connection.query("SELECT * FROM contas", (err, row, fields)=> {

More info: https://www.w3schools.com/nodejs/nodejs_modules.asp

Edited by valdirdd
Link to comment
Share on other sites

  • 8 months later...

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