I'm currently writing an app where I am querying my MySQL database table that has three rows. I want to save each of the rows as a variable/string.
E.g SELECT * FROM orders LIMIT 1 where the response is
[
RowDataPacket {
orderid: 1,
email: 'isadg232323fskdjghfjkhbdfkjhsdf@gmail.com',
token: 'ABCDEF4TZX1A9G7Z'
}
]
How do I extract the email from the result and set it as a variable such as "email" for future use in my app.
My current code:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "123.456.123.456",
user: "user",
password: "pass",
database: "db"
});
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM orders LIMIT 1", function (err, result, fields) {
if (err) throw err;
console.log(result);
con.end();
});
});