ajax.php 1.2 KB

123456789101112131415161718192021222324
  1. <?php
  2. require("connection.php");
  3. // Opens a connection to a MySQL server
  4. $pdo = new PDO("mysql:host=$dbhost;dbname=$db;charset=utf8mb4", $dbuser, $dbpass);
  5. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  6. $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  7. $stmtEvents = $pdo->prepare("SELECT channelEvent.channelId, UNIX_TIMESTAMP(channelEvent.date), channelEvent.clientCount FROM channelEvent
  8. LEFT JOIN channel on channel.id = channelEvent.channelId
  9. LEFT JOIN server ON server.id = channel.serverId
  10. WHERE server.uid = ?
  11. ORDER BY date ASC LIMIT 10000");
  12. $stmtEvents->execute(Array($serverUid));
  13. $stmtChannel = $pdo->prepare("SELECT channel.id, channel.name, channel.channelId, channel.parentId, channel.position, channel.description, server.name as serverName, server.id as serverId FROM channel
  14. LEFT JOIN server ON server.id = channel.serverId
  15. WHERE server.uid = ?");
  16. $stmtChannel->execute(Array($serverUid));
  17. $json = Array(
  18. "eventColumns" => Array("id", "date", "clientCount"),
  19. "events" => $stmtEvents->fetchAll(PDO::FETCH_NUM),
  20. "channels" => $stmtChannel->fetchAll(PDO::FETCH_ASSOC)
  21. );
  22. echo json_encode($json);
  23. ?>