- MySQL 모듈
- npm install mysql
- require('mysql')
- MySQL Connection
var mysql = require('mysql');
var conn = mysql.createConnection({
host: 'localhost',
user : 'root',
password : 'admin',
database : 'test'
});
conn.connect(function(err){
if(err){
console.log(err);
}else{
console.log('mysql connected.');
}
});
- SELECT
conn.query('SELECT * FROM BOARD', function(err, results, fields){
//console.log(arguments);
for(var i=0; i<results.length; i++){
console.log( results[i]._id);
console.log(results[i][fields[1].name]);
console.log(results[i][fields[2].name]);
console.log(results[i].writer);
}
});
- INSERT
conn.query('INSERT INTO BOARD(title, content, writer) '+
' values( "title-new", "conetn-new", "zzz") ',
function(err, results, fiels){
console.log(arguments);
});
- UPDATE
conn.query('UPDATE BOARD SET writer =? WHERE writer=?',
['abc', 'aaa'],
function(err, results, fields){
console.log(arguments);
});
- DELETE
var sql = 'DELETE FROM BOARD WHERE writer=?';
conn.query(sql, ['bbb'], function(err, results){
console.log(arguments);
});
'Programming > 웹프로그래밍' 카테고리의 다른 글
[NodeJs] C++ Addon 하는 방법 (설치/속성/메서드/파라미터,리턴/callback/객체생성반환/함수생성/C++객체생성) (0) | 2016.03.18 |
---|---|
[NodeJs] NoSQL MongoDB 연동하기 (검색/추가/삭제/갱신) (0) | 2016.03.18 |
[NodeJs] Socket.io를 이용해 간단한 채팅(Chatting) 만들기. (0) | 2016.03.18 |
[NodeJs] Socket.io를 WebSocket 구현하기. (0) | 2016.03.18 |
[NodeJs] Socket.IO란? (0) | 2016.03.18 |