当前位置:网站首页>node js 保持长连接
node js 保持长连接
2022-07-08 00:25: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个小时发送一次 1小时 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');
//检验这个密码有没有注册过
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('该用户名已存在!!');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('添加成功');location.href='/admin/admin/add';</script>");
} else {
res.send("<script>alert('添加失败');history.go(-1);</script>");
}
console.log(result);
//res.send("<script>alert('管理员添加成功!!');</script>");
})
})边栏推荐
- Chapter 7 behavior level modeling
- About snake equation (5)
- Get familiar with XML parsing quickly
- The persistence mode of redis - RDB and AOF persistence mechanisms
- cv2-drawline
- Mouse event - event object
- Euler Lagrange equation
- C语言-模块化-Clion(静态库,动态库)使用
- 用户之声 | 对于GBase 8a数据库学习的感悟
- Remote sensing contribution experience sharing
猜你喜欢

Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)

C语言-Cmake-CMakeLists.txt教程

2、TD+Learning

Understanding of maximum likelihood estimation

C language - modularization -clion (static library, dynamic library) use

Remote sensing contribution experience sharing

Partage d'expériences de contribution à distance

【目标跟踪】|DiMP: Learning Discriminative Model Prediction for Tracking

滑环使用如何固定

Version 2.0 of tapdata, the open source live data platform, has been released
随机推荐
The numerical value of the number of figures thought of by the real-time update of the ranking list
Usage of hydraulic rotary joint
ANSI / NEMA- MW- 1000-2020 磁铁线标准。. 最新原版
cv2读取视频-并保存图像或视频
regular expression
COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况----几何模型的建立
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
Matlab method is good~
Redux usage
Different methods for setting headers of different pages in word (the same for footer and page number)
Remote Sensing投稿經驗分享
How does Matplotlib and PIL image integrate and save multiple pictures into one picture
Introduction to grpc for cloud native application development
子矩阵的和
Remote Sensing投稿经验分享
MySQL数据库(2)
腾讯游戏客户端开发面试 (Unity + Cocos) 双重轰炸 社招6轮面试
How does Matplotlib generate multiple pictures in turn & only save these pictures without displaying them in the compiler
Introduction to natural language processing (NLP) based on transformers
Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences