当前位置:网站首页>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>");
})
})
边栏推荐
- C语言-Cmake-CMakeLists.txt教程
- About snake equation (5)
- common commands
- Redisson分布式锁解锁异常
- 神经网络与深度学习-5- 感知机-PyTorch
- [target tracking] |dimp: learning discriminative model prediction for tracking
- Optimization of ecological | Lake Warehouse Integration: gbase 8A MPP + xeos
- 用户之声 | 冬去春来,静待花开 ——浅谈GBase 8a学习感悟
- Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences
- Sword finger offer II 041 Average value of sliding window
猜你喜欢
碳刷滑环在发电机中的作用
Introduction to grpc for cloud native application development
COMSOL - Construction of micro resistance beam model - final temperature distribution and deformation - establishment of geometric model
adb工具介绍
为什么更新了 DNS 记录不生效?
Summary of log feature selection (based on Tianchi competition)
Redux使用
Why did MySQL query not go to the index? This article will give you a comprehensive analysis
Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
写一个纯手写的qt的hello world
随机推荐
Mysql database (2)
ClickHouse原理解析与应用实践》读书笔记(8)
Version 2.0 de tapdata, Open Source Live Data Platform est maintenant disponible
Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences
[target tracking] |dimp: learning discriminative model prediction for tracking
C language - modularization -clion (static library, dynamic library) use
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
burpsuite
不算不知道,花呗分期的真实利率居然这么高
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences
Nacos microservice gateway component +swagger2 interface generation
Tencent game client development interview (unity + cocos) double bombing social recruitment 6 rounds of interviews
滑环使用如何固定
【目标跟踪】|atom
子矩阵的和
powerbuilder 中使用线程的方法
Matlab r2021b installing libsvm
快速熟知XML解析
2022国内十大工业级三维视觉引导企业一览