Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- NODE and MySQL Example
- */
- var mysql = require('mysql');
- const readline = require('readline').createInterface({
- input: process.stdin,
- output: process.stdout
- })
- const con = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "helloworld",
- database: "school"
- });
- con.connect( (err) => {
- if (err) throw err;
- let sql = "SELECT * FROM student";
- con.query(sql, (err, result) => {
- if (err) throw err;
- let data = JSON.parse(JSON.stringify(result));
- for (const row of data) {
- console.log(row.name);
- }
- readline.question("Type name of student: ", (name) => {
- readline.close();
- sql = `SELECT email FROM student WHERE name = "${name}"`;
- con.query(sql, (err, result) => {
- let data = JSON.parse(JSON.stringify(result));
- for (const row of data) {
- console.log(row.email);
- }
- con.end();
- process.exit();
- });
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement