Advertisement
Guest User

Untitled

a guest
May 11th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /**
  2. * Created by dimbo on 02.05.2017.
  3. */
  4. var mysql = require("mysql");
  5. var readline = require('readline')
  6.  
  7. // First you need to create a connection to the db
  8. var connection = mysql.createConnection({
  9. host: "localhost",
  10. port: "3306",
  11. user: "root",
  12. password: "DIMbot%5452332",
  13. database : 'userlogin'
  14. });
  15.  
  16. connection.connect(function (err) {
  17. if(err){
  18. console.log('Eror connecting to database');
  19. }
  20. });
  21. var r1=readline.createInterface({
  22. input:process.stdin,
  23. output:process.stdout
  24. });
  25.  
  26. r1.question('Enter User id', (id)=>{
  27. var user = {userId:id};
  28. r1.question('Enter User name', (name)=>{
  29. var user = {userName:name, userId:id};
  30. connection.query('INSERT INTO users SET ?', user, function(err,res) {
  31. if(err) throw err
  32. });
  33. });
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement