慕盖茨4494581
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 接着使用nodejs对数据库进行增删改查: //引入mysql模块var mysql = require('mysql');//链接数据库var connection = mysql.createConnection({ host:'localhost', user:'root', password:'root', database:'node',})connection.connect();//查询数据var sql = 'SELECT * FROM user';connection.query(sql,function (err,result) { if(err){ console.log('error'); return; } console.log('-----------------查询----------------'); console.log(result); console.log('-----------------查询结束----------------');}) //增加数据var addsql = 'INSERT INTO user(name,age,sex) VALUES(?,?,?)';var addsqlparams = ['汪丹萍','24','女'];connection.query(addsql,addsqlparams,function (err,result) { if(err){ console.log('error'); return; } console.log('-----------------新增成功----------------'); console.log(result); console.log('-----------------结束----------------');}) //修改数据var modsql = 'UPDATE user SET name = ?,age = ? WHERE id = ?';var modsqlparams = ['吕雪源love','26','1'];connection.query(modsql,modsqlparams,function (err,result) { if(err){ console.log('err'); return; } console.log('--------------------------------'); console.log(result); console.log('--------------------------------');}) //删除数据var delsql = 'DELETE FROM user where id = 2';connection.query(delsql,function (err,result) { if(err){ console.log('err'); return; } console.log('----------删除-------------'); console.log(result);}) connection.end();