风一样的回忆

新浪微薄腾讯微薄

最新碎语:最近开始学习俄语!!!

您的位置:风一样的回忆 >未分类> nodejs

nodejs

var sys = require('mysql');

var DATABASE = 'cooperation';
var TABLE = 'cooperation';
var conn = sys.createConnection({
	host	:'localhost',
	database:'cooperation',
	port	:'3306',
	user	:'root',
	password:'root',
});
conn.connect(function(error, results){
	if(error) {
		console.log('Connection Error:'	+	error.message);
		return;
	}
	//console.log('Connected to MySQL');
});

conn.query("use " + DATABASE);
conn.query('SELECT * FROM '+TABLE+' ',function selectCb(err, results, fields) {
	if(err) {
		throw err;
	}

	if(results) {
		for(var i = 0;i< results.length;i++){
			console.log("%d\t%s\t%s", results[i].id, results[i].name, results[i].create_time);
		}
	}
	//console.log(results);

	conn.end();

});

---

转载请注明本文标题和链接:《nodejs

分享到:

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交