Jump to content

Recommended Posts

Posted

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

Posted (edited)

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
  • 8 months later...
Posted
$mysearch="Your Search Name";
$query = mysql_query("SELECT * FROM table");
$c=0;
// set array
$array = array();

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

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

for($i=0;$i=$c;$i++)
{
if($array[i]['username']==$mysearch)
{
// name found
}
}

https://www.welookups.com/

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