adminerevo/plugins/master-slave.php

44 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2013-02-22 12:22:02 +00:00
<?php
/** Execute writes on master and reads on slave
2015-09-08 16:23:25 +00:00
* @link https://www.adminer.org/plugins/#use
2017-02-27 12:43:33 +00:00
* @author Jakub Vrana, https://www.vrana.cz/
2018-01-14 10:03:54 +00:00
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
2013-02-22 12:22:02 +00:00
*/
class AdminerMasterSlave {
private $masters = array();
2013-05-08 18:29:19 +00:00
/**
2013-02-22 12:22:02 +00:00
* @param array ($slave => $master)
*/
2015-08-15 15:04:21 +00:00
function __construct($masters) {
2013-02-22 12:22:02 +00:00
$this->masters = $masters;
}
function credentials() {
if ($_POST && isset($this->masters[SERVER])) {
return array($this->masters[SERVER], $_GET["username"], get_session("pwds"));
}
}
function login($login, $password) {
if (!$_POST && ($master = &$_SESSION["master"])) {
$connection = connection();
$connection->query("DO MASTER_POS_WAIT('" . q($master['File']) . "', $master[Position])");
$master = null;
}
}
function messageQuery($query, $time, $failed = false) {
2013-02-22 12:22:02 +00:00
//! doesn't work with sql.inc.php
$connection = connection();
$result = $connection->query('SHOW MASTER STATUS');
if ($result) {
restart_session();
$_SESSION["master"] = $result->fetch_assoc();
}
}
}