-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmysqlTest.js
More file actions
43 lines (36 loc) · 1.07 KB
/
mysqlTest.js
File metadata and controls
43 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var http = require('http'),
mysql = require('db-mysql'),
generic_pool = require('generic-pool');
var pool = generic_pool.Pool({
name: 'mysql',
max: 10,
create: function(callback) {
new mysql.Database({
hostname: 'localhost',
user: 'root',
password: 'anjwl?',
database: 'biblewiki'
}).connect(function(err, server) {
callback(err, this);
});
},
destroy: function(db) {
db.disconnect();
}
});
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
pool.acquire(function(err, db) {
if (err) {
return res.end("CONNECTION error: " + err);
}
db.query().select('*').from('user').execute(function(err, rows, columns) {
pool.release(db);
if (err) {
return res.end("QUERY ERROR: " + err);
}
res.end(rows[0]["user_name"].toString());
});
});
}).listen(8080);
console.log('Server running at http://127.0.0.1:8001/');