Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在系统中提供最近活动的最佳方法是什么_Mysql_Express_Architecture_System - Fatal编程技术网

Mysql 在系统中提供最近活动的最佳方法是什么

Mysql 在系统中提供最近活动的最佳方法是什么,mysql,express,architecture,system,Mysql,Express,Architecture,System,我需要在我的系统中保存用户最近的活动。你知道我该怎么做吗? 有文章的链接吗? Im使用在节点上运行的ExpressJS作为服务器 提前感谢。这取决于哪些操作应保存为用户活动 要处理GET/POST请求,请执行以下操作: 在MySQL Workbench中使用表«requests»创建名为«activity»的MySQL数据库,如下所示: 通过键入以下命令安装官方MySQL连接器 npm install @mysql/xdevapi --save --save-exact 打开您的inde

我需要在我的系统中保存用户最近的活动。你知道我该怎么做吗? 有文章的链接吗? Im使用在节点上运行的ExpressJS作为服务器


提前感谢。

这取决于哪些操作应保存为用户活动
要处理GET/POST请求,请执行以下操作:

  • 在MySQL Workbench中使用表«requests»创建名为«activity»的MySQL数据库,如下所示:
  • 通过键入以下命令安装官方MySQL连接器

     npm install @mysql/xdevapi --save --save-exact
    
  • 打开您的index.js并放置如下内容:

     const express = require('express');
     const mysqlx = require('@mysql/xdevapi');
    
     const app = express();
    
     function log(url) {
       mysqlx.getSession('dbLogin:dbPassword@localhost:33060')
     .then(session => {
       session
         .getSchema('activity')
         .getTable('requests')
         .insert([ 'username', 'url' ])
         .values([ 'User', url ])
         .execute();
     });
     }
    
     app.get('/', (req, res) => {
       log(req.url);
       res.sendFile(__dirname + '/index.html');
     });
    
     app.get('/info', (req, res) => {
       log(req.url);
       res.sendFile(__dirname + '/info.html');
     });
    
     app.listen(3000);
    

  • 有关鼠标/键盘事件等更详细的信息,您可以使用AJAX()或使用

    发送POST请求这解释了事情的后端,谢谢@razor3x,但是如果我使用react作为前端,前端的路由实际上不会通过rest api调用发送到后端,对吗?因此,除非我发送带有api调用的路由并将其保存在数据库中(如您清楚解释的),否则还有其他方法可以获取前端到数据库的路由吗?