connecting node to mysql code example
Example 1: use nodejs mysql
var mysql = require('mysql');var connection = mysql.createConnection({ host : 'localhost', user : 'me', password : 'secret', database : 'my_db'}); connection.connect(); connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) { if (error) throw error; console.log('The solution is: ', results[0].solution);}); connection.end();
Example 2: js read mysql database
const config = {
"table" : "customers",
"limit" : "50",
"offset" : "0"
};
_POST_REQUEST("link-to-server/database.php", 'config=' + JSON.stringify(config), (response) => {
var data = JSON.parse(response);
});