summaryrefslogtreecommitdiff
path: root/lib/mysql.php
blob: 6d575adf77b529154f98e0ff3d6582b50aa2a7ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

# do not include twice
if (isset($mysql))
  return;

require_once "../init.php";
include_once BASE . "/lib/http.php";

$mysql = new mysqli("localhost", "webserver", "empty", "buildmaster");
if ( $mysql -> connect_error ) {
  die_500( "Connection failed: " . $mysql -> connect_error );
}

function mysql_run_query($query) {
  global $mysql;
  if ( ! $result = $mysql -> query($query) )
    die_500( "Query failed: " .  $mysql -> error );
  return $result;
}

function show_warning_on_offline_slave() {
  $result = mysql_run_query(
    "SHOW STATUS LIKE \"Slave_running\""
  );
  if (($result -> num_rows == 0) ||
    ($result -> fetch_assoc() ["Value"] != "ON")) {
    $result = mysql_run_query(
      "SELECT 1 FROM `ssh_log`" .
      " WHERE ADDTIME(`ssh_log`.`date`,\"1:00\")>NOW()" .
      " LIMIT 1"
    );
    if ($result -> num_rows == 0) {
      print "<div><font color=\"ff0000\">The replication slave is currently not running. The database might be outdated.</font></div>\n";
    }
  }
}