Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. var mysql=require('mysql');
  2. var client=mysql.createClient({
  3. user:'mysql',
  4. password:''
  5. });
  6. client.useDatabase('test');
  7. module.exports.get_chapter_list = function(subject_id){
  8.  
  9. client.query("select distinct chapter_id from course_associations where subject_id="+subject_id+" and status_id=1",
  10. function(err,results,fields){
  11. return results;
  12. });
  13. return "hello";
  14. };
  15.  
  16. rs=require('./getChapterList');
  17.  
  18. rs.get_chapter_list(1);
  19.  
  20. // Output: hello
  21.  
  22. var mysql=require('mysql');
  23. var client=mysql.createClient({
  24. user:'mysql',
  25. password:''
  26. });
  27. client.useDatabase('test');
  28. module.exports.get_chapter_list = function(subject_id, callback){
  29. client.query("select distinct chapter_id from course_associations where subject_id="+subject_id+" and status_id=1",
  30. function(err,results,fields){
  31. callback( results );
  32. });
  33. return "hello";
  34. };
  35.  
  36. var rs = require('./getChapterList');
  37.  
  38. rs.get_chapter_list(1, function(results) {
  39. console.log(results);
  40. }
  41. });
  42.  
  43. module.exports.get_chapter_list = function(subject_id, callback){
  44. client.query("select distinct chapter_id from course_associations where subject_id="+subject_id+" and status_id=1",
  45. function(err,results,fields){
  46. // doesn't contain any error handling
  47. callback(results);
  48. });
  49. };
  50.  
  51. rs.get_chapter_list(1, function(results) {
  52. console.log(results); // or whatever you need to do with the results
  53. });
  54.  
  55. exports.get_chapter_list = function(subject_id, callback) {
  56. client.query("select ...", callback);
  57. };
  58.  
  59. ...
  60.  
  61. var rs = require('./getChapterList');
  62.  
  63. rs.get_chapter_list(1, function(err, results) {
  64. if (err) {
  65. // handle error
  66. } else {
  67. // do something with results
  68. console.log(results);
  69. }
  70. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement