1
2//put these lines in a seperate file
3const mysql = require('mysql2');
4
5const connection = mysql.createPool({
6 host: "localhost",
7 user: "",
8 password: "",
9 database: ""
10 // here you can set connection limits and so on
11});
12
13module.exports = connection;
14
15//put these on destination page
16const connection = require('../util/connection');
17
18async function getAll() {
19 const sql = "SELECT * FROM tableName";
20 const [rows] = await connection.promise().query(sql);
21 return rows;
22}
23exports.getAll = getAll;
1// Use https://github.com/JackChilds/jsmysqldb
2
3// Then once it's setup you can just do this:
4
5// Config that will be sent to server
6const config = {
7 "table" : "customers",
8 "limit" : "50",
9 "offset" : "0"
10};
11
12// Use the _POST_REQUEST function to send data to the server and get a response
13_POST_REQUEST("link-to-server/database.php", 'config=' + JSON.stringify(config), (response) => {
14 // Convert the response into an array of rows:
15 var data = JSON.parse(response);
16 // Now do what you want with data
17 // data[row index][column name]
18});