Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dependencies
- var mysql = require("mysql");
- // db connection settings
- var con = mysql.createConnection({
- host:"localhost",
- user:"root",
- password:"xxxxxx",
- database:"xxxx"
- });
- // connect to the database
- con.connect(function(err){
- if(err)
- console.log(err)
- else
- var sql = "SELECT * FROM employee WHERE emp_id = 4";
- con.query(sql, function(err, data){
- if(err){
- console.log(err)
- }
- else{
- console.log(data.sex);
- }
- });
- });
- here is the query result
- [ RowDataPacket {
- emp_id: 4,
- first_name: 'Micheal',
- last_name: 'Scott',
- birth_date: 1964-06-04T07:00:00.000Z,
- sex: 'M',
- salary: 75000,
- super_id: 2,
- branch_id: null } ]
Add Comment
Please, Sign In to add comment