各位大神有没有操作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();
@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); });
这样才是正解