当前位置:网站首页>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>");
})
})
边栏推荐
- 用户之声 | 对于GBase 8a数据库学习的感悟
- 不算不知道,花呗分期的真实利率居然这么高
- GBASE观察 | 数据泄露频发 信息系统安全应如何守护
- 【SolidWorks】修改工程图格式
- The foreach map in JS cannot jump out of the loop problem and whether foreach will modify the original array
- powerbuilder 中使用线程的方法
- About snake equation (5)
- common commands
- 城市土地利用分布数据/城市功能区划分布数据/城市poi感兴趣点/植被类型分布
- Tapdata 的 2.0 版 ,開源的 Live Data Platform 現已發布
猜你喜欢
给刚入门或者准备转行网络工程师的朋友一些建议
快速熟知XML解析
不算不知道,花呗分期的真实利率居然这么高
第七章 行为级建模
pb9.0 insert ole control 错误的修复工具
ANSI / nema- mw- 1000-2020 magnetic iron wire standard Latest original
微信小程序uniapp页面无法跳转:“navigateTo:fail can not navigateTo a tabbar page“
Get familiar with XML parsing quickly
Android 创建的sqlite3数据存放位置
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
随机推荐
跨模态语义关联对齐检索-图像文本匹配(Image-Text Matching)
图解网络:揭开TCP四次挥手背后的原理,结合男女朋友分手的例子,通俗易懂
用户之声 | 对于GBase 8a数据库学习的感悟
Get familiar with XML parsing quickly
写一个纯手写的qt的hello world
MySQL查询为什么没走索引?这篇文章带你全面解析
Tapdata 的 2.0 版 ,開源的 Live Data Platform 現已發布
软件测试笔试题你会吗?
QT -- package the program -- don't install qt- you can run it directly
Version 2.0 of tapdata, the open source live data platform, has been released
How to make the conductive slip ring signal better
QML fonts use pixelsize to adapt to the interface
Leetcode exercise - Sword finger offer 36 Binary search tree and bidirectional linked list
子矩阵的和
MySQL数据库(2)
I don't know. The real interest rate of Huabai installment is so high
发现值守设备被攻击后分析思路
body有8px的神秘边距
In depth analysis of ArrayList source code, from the most basic capacity expansion principle, to the magic iterator and fast fail mechanism, you have everything you want!!!
滑环在直驱电机转子的应用领域