Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mysql=require('mysql');
- var client=mysql.createClient({
- user:'mysql',
- password:''
- });
- client.useDatabase('test');
- module.exports.get_chapter_list = function(subject_id){
- client.query("select distinct chapter_id from course_associations where subject_id="+subject_id+" and status_id=1",
- function(err,results,fields){
- return results;
- });
- return "hello";
- };
- rs=require('./getChapterList');
- rs.get_chapter_list(1);
- // Output: hello
- var mysql=require('mysql');
- var client=mysql.createClient({
- user:'mysql',
- password:''
- });
- client.useDatabase('test');
- module.exports.get_chapter_list = function(subject_id, callback){
- client.query("select distinct chapter_id from course_associations where subject_id="+subject_id+" and status_id=1",
- function(err,results,fields){
- callback( results );
- });
- return "hello";
- };
- var rs = require('./getChapterList');
- rs.get_chapter_list(1, function(results) {
- console.log(results);
- }
- });
- module.exports.get_chapter_list = function(subject_id, callback){
- client.query("select distinct chapter_id from course_associations where subject_id="+subject_id+" and status_id=1",
- function(err,results,fields){
- // doesn't contain any error handling
- callback(results);
- });
- };
- rs.get_chapter_list(1, function(results) {
- console.log(results); // or whatever you need to do with the results
- });
- exports.get_chapter_list = function(subject_id, callback) {
- client.query("select ...", callback);
- };
- ...
- var rs = require('./getChapterList');
- rs.get_chapter_list(1, function(err, results) {
- if (err) {
- // handle error
- } else {
- // do something with results
- console.log(results);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement