各位大神有没有操作MySql的Demo啊,简单点的就行,不要特别复杂的,就直接是增删改查的操作就行,我都是看的MongoDB的,操作MySQL就不行了!谢谢各位指点下,
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();
我只想对您说三个字: 非常感谢您,我已经成功了!
你这个会失败吧,end不应该在回调里面?
@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); });
这样才是正解
11个字,不算标点符号
@hexie 它有pool的,用pool吧
这个不错