有没有操作MySql的Demo啊
 发布于 12 年前  作者 xiuxu123  5468 次预览  最后一次回复是 12 年前  来自  

各位大神有没有操作MySql的Demo啊,简单点的就行,不要特别复杂的,就直接是增删改查的操作就行,我都是看的MongoDB的,操作MySQL就不行了!谢谢各位指点下,

7 回复
hexie

var mysql = require(‘mysql’); var connection = mysql.createConnection({ host : ‘localhost’, user : ‘me’, password : ‘secret’, });

connection.connect();

connection.query(‘SELECT 1 + 1 AS solution’, function(err, rows, fields) { if (err) throw err;

console.log('The solution is: ', rows[0].solution); });

connection.end();

https://github.com/felixge/node-mysql

xiuxu123

我只想对您说三个字: 非常感谢您,我已经成功了!

sumory

你这个会失败吧,end不应该在回调里面?

hexie

@sumory 这个写法,的确不合理,官网给出的,不过实际上,还是能跑,

var mysql = require(‘mysql’); var connection = mysql.createConnection({ host : ‘localhost’, user : ‘me’, password : ‘secret’, });

connection.connect();

connection.query(‘SELECT 1 + 1 AS solution’, function(err, rows, fields) { connection.end(); if (err) throw err;

console.log('The solution is: ', rows[0].solution); });

这样才是正解

yakczh

11个字,不算标点符号

sumory

@hexie 它有pool的,用pool吧