var employeeDeleteSql_Params = 'Peter';
connection.query(employeeDeleteSql,employeeDeleteSql_Params,function(err,result){
if(err) console.log('[DELETE ERR]-',err.message);
console.log(result);
})
}deleteEmployee();
这样我们就可以愉快的操作数据库了
如果大家想把项目更模块化操作,可在model下面新建一个employee_two.js,代码如下
var mysql = require('mysql');var connection = mysql.createConnection({
host:'',
user:'root',
password:'',
database:'nodejs',
port:})connection.connect();/**
* 增加员工
* @param {String} employee
* @param {Function} callback
*/exports.addEmployee=function(employee,callback){
var employeeInsertSql = 'INSERT INTO employee(name,sex,age,email) VALUES(?,?,?,?)';
var employeeInsertSql_Params = [employee.name,employee.sex,employee.age,employee.email]
connection.query(employeeInsertSql,employeeInsertSql_Params,callback)}/**
* 更新员工
* @param {String} employee
* @param {Function} callback
*/exports.updateEmployee = function(name,age){
var employeeUpdateSql = "UPDATE employee SET name = ? WHERE age =?";
var employeeUpdateSql_Params = ['Peter',22];
connection.query(employeeUpdateSql,employeeUpdateSql_Params,function(err,result){
if(err) console.log('[UPDATE ERR]-',err.message);
console.log(result);
})}/**
* 查询员工
*
*/exports.getEmployee = function(){
var employeeGetSql = "SELECT * FROM employee";
connection.query(employeeGetSql,callback)}/**
* 删除员工
* @param {String} name
*/exports.deleteEmployee = function(name){
var employeeDeleteSql = "DELETE employee WHERE name = ?";
var employeeDeleteSql_Params = 'Peter';
connection.query(employeeDeleteSql,employeeDeleteSql_Params,callback)
}再在根目录下新建index.js,代码如下var db = require('./model/employee_two');//增加员工var employee = {
name:'lisa',
age:22,
sex:"女",
email:'99533212@qq.com'}db.addEmployee(employee,function(err,result){
if(err) console.log("[INSERT err]-",err.message)
console.log(result);})//删除员工db.deleteEmployee('Peter',function(err,result){
if(err) console.log("[DELETE err]-",err.message)
console.log(result);})//更新员工db.updateEmployee('Tim',23,function(err,result){
if(err) console.log("[UPDATE err]-",err.message)
console.log(result);})//查询员工db.getEmployee(function(err,result){
if(err) console.log("[GET err]-",err.message)
console.log(result);})
【腾讯云的mysql怎么用 腾讯云服务器部署mysql】关于腾讯云的mysql怎么用和腾讯云服务器部署mysql的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。
推荐阅读
- 电商企业如何晋升,如何从事电商行业
- 数列关系小程序怎么做,数列关系小程序怎么做的
- 河源专业sap优化服务的简单介绍
- 什么游戏可以模拟经商游戏,模拟经商的手游
- linux检查内存命令 linux 检测内存
- asp.net导游人员管理系统,导游服务管理平台
- 苹果怎样pdf转word,苹果如何把pdf转换成word文档
- php排队处理数据 php排队等待请求
- c语言堆栈有什么区别,c语言有堆栈的概念么