-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.js
43 lines (36 loc) · 1.04 KB
/
mysql.js
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
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'twitter_map'
});
function connect(){
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('connected as id ' + connection.threadId);
});
}
//console.log(result[i].content);
function findall(){
var sql = "select * from twitter";
connection.query(sql,function(err,result){
});
}
function insertone(parameters){
var sql = "INSERT INTO twitter VALUES(?,?,?,?,?)";
var id = parameters.id;
var content = parameters.content;
var country = parameters.country;
var longitude = parameters.longitude;
var latitude = parameters.latitude;
var inserts = [id,content,country,longitude,latitude];
sql = mysql.format(sql, inserts);
connection.query(sql,function(err,result){
for (i=0;i<result.length;++i)
console.log(result[i].content);
});
}