-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdao.js
60 lines (49 loc) · 1.74 KB
/
dao.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var mysql = require('mysql');
Dao={
connection: mysql.createConnection({
host: 'localhost',
user: 'local',
password: '123456789123456789',
database: 'FREECHAT'
}),
result:undefined,
init:function(){
this.connection.connect(function(error){
if(error)
console.log('Error');
else
console.log('Conexion correcta.');
});
},
finish:function(){
this.connection.end();
}
,
select: function(callback){
this.connection.query("SELECT EMISOR,MSJ FROM MENSAJE", function(error, result,fields){
if(error)
throw error;
else{
if(result.length > 0)
callback(result);
else
console.log('Registro no encontrado');
}
});
},
insert:function(emisor,msj){
this.connection.query("INSERT INTO MENSAJE (EMISOR,MSJ) VALUES( '"+emisor+"' , '"+msj+"' )",function(error){
if(error)
throw error;
else
console.log("insercion correcto");
});
}
};
Dao.init();
//Dao.init();
//Dao.select(function(result){Dao.result=result;console.log(Dao.result);});
//Dao.finish();
/*
Creado por: Carlos Chavez Laguna.
*/