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: ""
    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:

Edited by valdirdd

Share this post

Link to post
Share on other sites
$mysearch="Your Search Name";
$query = mysql_query("SELECT * FROM table");
// set array
$array = array();

// look through query
while($row = mysql_fetch_assoc($query)){

  // add each row returned into an array
  $array[] = $row;

// name found

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.