Guest User

Untitled

a guest
Sep 13th, 2018
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. var mysql = require('mysql');
  2.  
  3. var con = mysql.createConnection({
  4. host: "localhost",
  5. user: "root",
  6. password: "neymarrocks1"
  7. });
  8.  
  9. con.connect(function(err) {
  10. if (err) throw err;
  11. console.log("Connected!");
  12. /*Create a database named "mydb":*/
  13. con.query("CREATE DATABASE names", function (err, result) {
  14. if (err) throw err;
  15. console.log("Database created");
  16. });
  17. });
  18.  
  19. var mysql = require('mysql');
  20.  
  21. var con = mysql.createConnection({
  22. host: "localhost",
  23. user: "root",
  24. password: "neymarrocks1",
  25. database: "names"
  26. });
  27.  
  28. con.connect(function(err) {
  29. if (err) throw err;
  30. console.log("Connected!");
  31. /*Create a table named "customers":*/
  32. var sql = "CREATE TABLE people (id INT AUTO_INCREMENT PRIMARY KEY, firstName VARCHAR(255), lastName VARCHAR(255))";
  33. con.query(sql, function (err, result) {
  34. if (err) throw err;
  35. console.log("Table created");
  36. });
  37. });
  38.  
  39. var mysql = require('mysql');
  40.  
  41. var con = mysql.createConnection({
  42. host: "localhost",
  43. user: "root",
  44. password: "neymarrocks1",
  45. database: "names"
  46. });
  47.  
  48. con.connect(function(err) {
  49. if (err) throw err;
  50. console.log("Connected!");
  51. var sql = "INSERT INTO people (firstName, lastName) VALUES ?";
  52. var peoplenames = [
  53. ['Vedant', 'Apte'],
  54. ['Vedant', 'Savalajkar'],
  55. ['Vinay', 'Apte'],
  56. ['Varda', 'Apte'],
  57. ['Mihir', 'Wadekar'],
  58. ['Mihir', 'Kulkarni'],
  59. ['Eesha', 'Hazarika'],
  60. ['Eesha', 'Gupte'],
  61. ['Raunak', 'Sahu'],
  62. ['Hritvik', 'Agarwal'],
  63. ['Mahima', 'Kale'],
  64. ['Shivani', 'Sheth'],
  65. ['Arya', 'Chheda'],
  66. ['Diya', 'Shenoy']
  67. ];
  68. con.query(sql, [peoplenames], function (err, result) {
  69. if (err) throw err;
  70. console.log("Number of records inserted: " + result.affectedRows);
  71. });
  72. });
Add Comment
Please, Sign In to add comment