Created
July 5, 2016 09:49
-
-
Save zenithtekla/c3b4aeaace1cab4a2cc5ac15a0adda9e to your computer and use it in GitHub Desktop.
working script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import modules | |
var express = require('express'); | |
var mysql = require('mysql'); | |
var app = express(); | |
// implement connectionPool | |
var connection = mysql.createPool({ | |
// properties ... | |
connectionLimit: 90, // only 90 queries at a time | |
host:'localhost', | |
user:'root', | |
password:'KTMEi', | |
database:'mantis_live_dev' | |
}); | |
app.get('/', function(req, res){ | |
// about mysql | |
// connection.query("SELECT * FROM mantis_live_dev WHERE", function(error, rows, fields)); | |
connection.getConnection(function(error, tempCont){ | |
if(!!error){ | |
tempCont.release(); | |
console.log('Error'); | |
} else { | |
console.log('Successfully connected.'); | |
var query1 = "SELECT * FROM mysampletable WHERE id>10"; | |
tempCont.query(query1, function(error, rows, fields){ | |
tempCont.release(); | |
// callback | |
if(!!error){ | |
console.log('Error in the query'); | |
} else { | |
console.log('Success!\n'); | |
console.log(rows); | |
// res.send('Hello, ' + rows[0].Name); | |
res.json(rows); | |
// parse with your rows/ fields | |
} | |
}); | |
} | |
}) | |
}); | |
app.listen(1337); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment