Guest User

Untitled

a guest
Jan 25th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. // dependencies
  2. var mysql = require("mysql");
  3. // db connection settings
  4. var con = mysql.createConnection({
  5. host:"localhost",
  6. user:"root",
  7. password:"xxxxxx",
  8. database:"xxxx"
  9. });
  10.  
  11. // connect to the database
  12.  
  13. con.connect(function(err){
  14. if(err)
  15. console.log(err)
  16. else
  17. var sql = "SELECT * FROM employee WHERE emp_id = 4";
  18. con.query(sql, function(err, data){
  19. if(err){
  20. console.log(err)
  21. }
  22. else{
  23. console.log(data.sex);
  24. }
  25. });
  26. });
  27.  
  28. here is the query result
  29.  
  30. [ RowDataPacket {
  31. emp_id: 4,
  32. first_name: 'Micheal',
  33. last_name: 'Scott',
  34. birth_date: 1964-06-04T07:00:00.000Z,
  35. sex: 'M',
  36. salary: 75000,
  37. super_id: 2,
  38. branch_id: null } ]
Add Comment
Please, Sign In to add comment