xiNY Posted May 21, 2018 Share Posted May 21, 2018 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 More sharing options...
valdirdd Posted May 23, 2018 Share Posted May 23, 2018 (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 May 23, 2018 by valdirdd Fix Link to comment Share on other sites More sharing options...
aditya12 Posted February 3, 2019 Share Posted February 3, 2019 $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/ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now