当前位置:网站首页>Node JS maintains a long connection
Node JS maintains a long connection
2022-07-08 01:52:00 【sunyin. liu】
const mysql = require('mysql');
const connect = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'blog'
});
connect.connect();
function keepalive (connect) {
connect.query('select 1', [], function (err, result) {
if (err) return console.log(err);
// Successul keepalive
});
}
//5 Send every hour 1 Hours 60 * 60
setInterval(() => { keepalive(connect) }, 60 * 60 * 5);
module.exports = connect;Cannot enqueue Handshake after invoking quit
node:events:505
let mysql = require('../../config/db.js');
// Check whether this password has been registered
var sql = `select id,username from blog_admin where username = '${username}'`;
console.log(sql);
mysql.query(sql, function (err, result) {
if (err) {
console.log('[SELECT ERROR] - ', err.message);
return;
}
if (result.length > 0) {
res.send("<script>alert(' The user name already exists !!');history.go(-1);</script>");
return;
}
var md5 = crypto.createHash('md5');
password = md5.update(password).digest('hex');
var time = Math.round(((new Date()).getTime()) / 1000);
var sql = `insert into blog_admin(username,password,status,time) values('${username}','${password}',${status},${time})`;
mysql.query(sql, function (err, result) {
if (err) {
console.log('[SELECT ERROR] - ', err.message);
return;
}
if (result.affectedRows == 1) {
res.send("<script>alert(' Add success ');location.href='/admin/admin/add';</script>");
} else {
res.send("<script>alert(' Add failure ');history.go(-1);</script>");
}
console.log(result);
//res.send("<script>alert(' Administrator added successfully !!');</script>");
})
})边栏推荐
- Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences
- 碳刷滑环在发电机中的作用
- How to make enterprise recruitment QR code?
- pb9.0 insert ole control 错误的修复工具
- QT -- package the program -- don't install qt- you can run it directly
- Remote sensing contribution experience sharing
- ArrayList源码深度剖析,从最基本的扩容原理,到魔幻的迭代器和fast-fail机制,你想要的这都有!!!
- Gbase observation | how to protect the security of information system with frequent data leakage
- Redisson分布式锁解锁异常
- 跨模态语义关联对齐检索-图像文本匹配(Image-Text Matching)
猜你喜欢

Optimization of ecological | Lake Warehouse Integration: gbase 8A MPP + xeos

用户之声 | 冬去春来,静待花开 ——浅谈GBase 8a学习感悟

Remote sensing contribution experience sharing

Summary of log feature selection (based on Tianchi competition)

Redux使用

神经网络与深度学习-5- 感知机-PyTorch

The foreach map in JS cannot jump out of the loop problem and whether foreach will modify the original array

nmap工具介紹及常用命令

About snake equation (5)

【目标跟踪】|atom
随机推荐
【目标跟踪】|DiMP: Learning Discriminative Model Prediction for Tracking
C language - modularization -clion (static library, dynamic library) use
nmap工具介紹及常用命令
Matlab r2021b installing libsvm
About snake equation (3)
regular expression
滑环在直驱电机转子的应用领域
How mysql/mariadb generates core files
node js 保持长连接
The function of carbon brush slip ring in generator
If time is a river
The numerical value of the number of figures thought of by the real-time update of the ranking list
城市土地利用分布数据/城市功能区划分布数据/城市poi感兴趣点/植被类型分布
发现值守设备被攻击后分析思路
能力贡献 GBASE三大解决方案入选“金融信创生态实验室-金融信创解决方案(第一批)”
cv2-drawline
静态路由配置全面详解,静态路由快速入门指南
QML fonts use pixelsize to adapt to the interface
Application of slip ring in direct drive motor rotor
【目标跟踪】|atom