【问题标题】:Get a notification on Windows whenever new data is put into my MySQL database每当将新数据放入我的 MySQL 数据库时,都会在 Windows 上收到通知
【发布时间】:2016-06-12 04:09:28
【问题描述】:

我有一个使用 wampserver 和 mysql 的基本本地网站。该网站的目的是让我家里的人可以要求我为他们下载东西。他们访问网站,输入他们想要的内容,然后将其发送到 mysql 中的数据库表。我想知道每当我获得新数据时是否有可能在 Windows 或其他方式上收到通知,以及我将如何去做。我正在考虑设置一个触发器以将新数据发送到我的电子邮件,但我更喜欢 Windows 通知。

【问题讨论】:

  • 我也遇到过这样的问题。对我来说,我被用作触发器。例如。
  • 嗨,Jar Yit,检查答案你也可以这样做

标签: php mysql


【解决方案1】:

简单的方法...

您可以做的是,您可以使用 Javascript 在时间循环中对服务器进行 ajax API 调用,因此如果有通​​知,它会显示一个弹出窗口。

一些基本指导如何做到这一点......

从服务器端

<?php
$output = array('status'=>0,'message'=>'');
$sql = "SELECT * FROM tbl_notification WHERE notification_tile > Time()";
$query = mysqli_query($conn,$sql);
if(mysqli_num_rows($query)>0){
     //these means there are some notification
    $output['status'] = 200;
    $output['message'] = mysql_fetch_all($query);
}

header('Content-Type:application/json');
echo json_encode($output);

在客户端

<div id="notification"></div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    setInterval(function(){
       //this loop will check for updates to the server for notifications
      $.get('server.php',function(data){
         if(data['status']==200){
               //this means there are some notifications available
             $('#notification').html(data['message']['notification_text'];
         }
      });
    },1000);
</script>

注意 假设您将 jquery 用于客户端,PHP 用于服务器,并且 mysql 数据库带有带有 id、notification_text 和 notification_time 作为字段的通知表...

祝你好运

【讨论】:

    【解决方案2】:

    有很多方法可以实现这一点(我敢打赌,许多 SO 用户会在这个领域提出建议)。但如果我是你,我会使用应用程序“电报”并在 MySQL 中插入任何记录时发送通知。

    1. 电报:Install the Telegram app
    2. StackOverflow question about posting to telegram

    【讨论】:

      猜你喜欢
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多