您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

NodeJS中MySql的增删改查基础写法的实现

2024/4/3 3:48:16发布23次查看
纯粹记录一下最基础写法,几乎没有写什么逻辑,写法也并不是很完善(因为我自己也刚刚摸索出来这么写可以...= =!)    望高手指教   也希望能够帮到比我还新的新手....
//1.insert操作
let insertsql = 'insert into user(username,password,name,gender,age) values (?,?,?,?,?)';
let insertparams = [username, password, name, gender, age];
mysqlconnection.query(insertsql, insertparams, function (error, results, fields) {
if (error)  throw error;
return results;
});
//2.select操作(我自己测试的时候发现,字符串类型的列,要给参数额外增加引号,否则会被当做数字类型或列名来进行处理)
let selectsql = 'select id from user where username = \''.concat(username, '\' and password = \'', password, '\'');
mysqlconnection.query(selectsql, function (error, results, fields) {
if(error) throw error;
return results;
});
//3.delete操作
let deletesql = 'delete from user where id = \''.concat(id, '\'');
mysqlconnection.query(deletesql, function (error, results, fields) {
if (error) throw error;
return results;
});
//4.update操作
let updatesql = 'update user set age = 30 where id = \''.concat(id, '\'');
mysqlconnection.query(updatesql, function (error, results, fields) {
if (error) throw error;
return results;
});
以上就是nodejs中mysql的增删改查基础写法的实现的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product