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;