Advertisement
Guest User

Untitled

a guest
Sep 5th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. var mysql=require('mysql');
  2.  
  3. var conn=mysql.createConnection({
  4. host: 'localhost',
  5. user: 'root',
  6. password: 'rootpass',
  7. database: 'mydb'
  8. });
  9.  
  10. conn.connect(function(err){
  11. if(err) throw err;
  12. console.log('Connected');
  13. });
  14. /*
  15. conn.query('CREATE DATABASE mydb', function(err, res){
  16. if(err) throw err;
  17. console.log(res);
  18. });
  19. */
  20.  
  21. conn.query('CREATE TABLE IF NOT EXISTS elev\
  22. (ID INT,\
  23. nume VARCHAR(20),\
  24. prenume VARCHAR(20),\
  25. clasa INT,\
  26. nota_mate INT)',
  27. function(err, res){
  28. if(err) throw err;
  29. console.log(res);
  30. });
  31. /*
  32. conn.query('INSERT INTO elev(ID, nume, prenume, clasa, nota_mate)\
  33. VALUES(1, "Popescu", "Ion", 9, 4)',
  34. function(err, res){
  35. if(err) throw err;
  36. console.log(res);
  37. });
  38. */
  39.  
  40. conn.query('SELECT * FROM elev', function(err, res){
  41. if(err) throw err;
  42. console.log(res);
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement