【问题标题】:Discord.js and mysql check for new database entry and output them?Discord.js 和 mysql 检查新的数据库条目并输出它们?
【发布时间】:2020-04-14 08:01:03
【问题描述】:

我将我的 mysql 数据库 与我的 nodejs discord bot 连接,我想检查我的表中是否有新条目并输出它们

我已经有了这个:

connection.query('SELECT steamid FROM banned ORDER BY ID DESC LIMIT 1', (err,rows) => {
    if (err) throw err;

    data = JSON.stringify(rows);
    console.log(rows[0]);
})

亲切的问候

【问题讨论】:

    标签: mysql discord.js


    【解决方案1】:

    试试这样的:

      /* Insert new thing into a database */
      let querySQL = 'SELECT steamid FROM banned ORDER BY ID DESC LIMIT 1';
      connection.query(querySQL)
        .then(results => {
          if (results.affectedRows > 0) {
            // Debug
            console.log(`SELECT results`, results);
            console.log(`1st result`, results[0]);
    
          }
        })
        .catch(e => {
          // Debug
          console.log(`[ERROR] SQL query`, e); 
        });
    

    阅读 npm 上的 mysql documentation 以获得更多帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 2017-04-02
      • 2013-02-01
      • 2021-12-09
      • 1970-01-01
      • 2018-04-19
      • 2015-02-08
      相关资源
      最近更新 更多