Advertisement
Guest User

Untitled

a guest
Oct 30th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. var mysql = require('mysql');
  2. var connection = mysql.createConnection({
  3. host : '127.0.0.1',
  4. user : 'root',
  5. password : '',
  6. database : 'chat'
  7. });
  8.  
  9. connection.connect(function(err) {
  10. if (err) throw err;
  11. });
  12.  
  13. module.exports = connection;
  14.  
  15. var db = require('./db');
  16. db.query('INSERT INTO messages SET ?', post, function(err, result) {
  17. if (err) throw err;
  18. });
  19.  
  20. var baza = require('./db.js');
  21.  
  22. function person(name, last){
  23. this.name = name;
  24. this.last = last;
  25. }
  26.  
  27. person.prototype.toConsole = function(){
  28. console.log(this.name+ " " + this.last);
  29. }
  30.  
  31. person.prototype.toString = function(){
  32. return this.name+ " " + this.last;
  33. }
  34.  
  35. person.prototype.writeToDB= function(){
  36. var sql = "INSERT INTO persons(id, name, last) VALUES (null, this.name, this.last)"; //i know string is not correctly written, it is just for idea.
  37. //I don't know what to do here
  38. }
  39.  
  40. module.exports = oseba;
  41.  
  42. var user = new person("John", "Smith");
  43. user.writeToDB();
  44.  
  45. var sql = "SELECT * FROM persons WHERE id = 5";
  46. //save rows[0] to var user = new person(rows[0].name, rows[0].last);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement