Sign in to follow this  
xiNY

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

Share this post


Link to post
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: ""
  });
  
connection.connect(function(err)
{
    if (err) throw err;
    console.log("Connected!");
});

module.exports.connection = connection;

Other file

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

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

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

Edited by valdirdd
Fix

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.