当前位置:网站首页>Node connects to the database for addition, deletion, modification and query
Node connects to the database for addition, deletion, modification and query
2022-07-18 01:24:00 【Su Xiaohua】
// The import module
const mysql =require("mysql")
// establish
const db=mysql.createPool({
host:"127.0.0.1",
user:"root",
password:"admin123",
database:'my_db_01',
})
// Check whether it is normal
db.query('SELECT 1',(err,resulys)=>{
if(err)return console.log(err)
console.log(resulys)
})
// // Insert
// const user={username:'xue123114111',userpassword:'234441111'}
// // perform sql placeholder
// const sqlStr1 ="insert into users(username,userpassword) values (?,?)"
// db.query(sqlStr1,[user.username,user.userpassword],(err,resulys)=>{
// if(err) return console.log(err)
// // Data returned successfully
// if(resulys.affectedRows===1) console.log(" success ")
// })
// // Portable insert
// const user1={username:'qian',userpassword:'111111',status:'1'}
// const sqlStr2 ="insert into users set ?"
// db.query(sqlStr2,user1,(err,resulys)=>{
// if(err) return console.log(err)
// // Data returned successfully
// if(resulys.affectedRows===1) console.log(" success ")
// })
// Inquire about
// const sqlStr="select * from users"
// db.query(sqlStr,(err,resulys)=>{
// if(err) return console.log(err)
// console.log(resulys)
// })
// Portable update
const user1={ id:5,username:'xue',userpassword:'0000',status:'0'}
const sqlStr2 ='update users set ? where id=?'
db.query(sqlStr2,[user1,user1.id],(err,resulys)=>{
if(err) return console.log(err)
// Data returned successfully
if(resulys.affectedRows===1) console.log(" The update is successful ")
})
// Delete
const sqlStr3='delete from users where id=?'
db.query(sqlStr3,5,(err,results)=>{
if(err) return console.log(err.message)
if(results.affectedRows===1){
console.log(" Delete data succeeded ")
}
})边栏推荐
- Leetcode - add two numbers
- I would like to ask you guys, how to save the status of this op with Flink SQL
- Let AI think like a baby! Deepmind "Plato" model published in nature
- 001 hierarchy selector
- QT | vs2017 + qt5.14.2 environment construction
- Free play noodles
- 手机浏览器产品分析
- 微信内H5页面唤起小程序&App
- How much do you know about programming paradigms -- clarify the mainstream programming paradigms
- 018.代理模式结和Filter做的一个屏蔽敏感词汇
猜你喜欢

北航学长的NLP赛事教程!

QT实现哈希表动态演示
QT | VS2017 + Qt5.14.2环境搭建

Q5对话框(模态和非模态)

A top-notch book and an ingenious translation! Machine learning and asset pricing is heavily listed

Penetration test CTF monograph

Q3 qmainwindow status bar riveted parts core parts

Matlab底层源码实现图像动态二值化

Important - Im open source project openim about version management and v2.3.0 release plan

基于注解配置扫描包
随机推荐
Matlab底层源码实现图像动态二值化
Matlab底层源代码实现Halcon scale_image_range(可用于背景分割)
常用SQL语句、存储过程和函数
I would like to ask you guys, how to save the status of this op with Flink SQL
Excuse me, sqlserver CDC to Kafka. Kafka has 12 partitions. There is a way to ensure that the same record is in the same partition
软件研发效能需求价值流分析专题
从0开始的 TypeScriptの十四:内置工具类型
Q4资源文件
ShareIt group's technology strategy - open, self-supporting and advanced layout
002 brief class loading process (1)
kali安装Nessus
Q3 QmainWindow 状态栏 铆接部件 核心部件
Q4资源文件2
SHAREit Group的技术战略——开放、自立、超前布局
Halcon常用图像预处理算子总结
对接企业微信,客户关系管理也可以很简单!
云原生:Docker实践经验(三)Docker 上部署 MySQL8 主从复制
A top-notch book and an ingenious translation! Machine learning and asset pricing is heavily listed
Practice teach you how to design WiFi voice broadcast schedule with stm32
Working sql: it is required that the average number of awards cannot be displayed by ranking