Files
adminer/plugins/master-slave.php

43 lines
1.2 KiB
PHP
Raw Normal View History

2013-02-22 04:22:02 -08:00
<?php
/** Execute writes on master and reads on slave
2015-09-08 09:23:25 -07:00
* @link https://www.adminer.org/plugins/#use
2017-02-27 13:43:33 +01:00
* @author Jakub Vrana, https://www.vrana.cz/
2018-01-14 11:03:54 +01: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 04:22:02 -08:00
*/
class AdminerMasterSlave {
private $masters = array();
2025-02-21 13:53:18 +01:00
2013-05-08 11:29:19 -07:00
/**
2025-02-23 14:37:40 +01:00
* @param array [$slave => $master]
2013-02-22 04:22:02 -08:00
*/
2015-08-15 17:04:21 +02:00
function __construct($masters) {
2013-02-22 04:22:02 -08:00
$this->masters = $masters;
}
2025-02-21 13:53:18 +01:00
2013-02-22 04:22:02 -08:00
function credentials() {
2025-03-06 17:34:21 +01:00
if ($_POST && isset($this->masters[Adminer\SERVER])) {
2025-03-08 17:32:52 +01:00
return array($this->masters[Adminer\SERVER], $_GET["username"], Adminer\get_session("pwds"));
2013-02-22 04:22:02 -08:00
}
}
2025-02-21 13:53:18 +01:00
2013-02-22 04:22:02 -08:00
function login($login, $password) {
if (!$_POST && ($master = &$_SESSION["master"])) {
2025-03-05 11:40:56 +01:00
$connection = Adminer\connection();
$connection->query("DO MASTER_POS_WAIT('" . Adminer\q($master['File']) . "', $master[Position])");
2013-02-22 04:22:02 -08:00
$master = null;
}
}
function messageQuery($query, $time, $failed = false) {
2013-02-22 04:22:02 -08:00
//! doesn't work with sql.inc.php
2025-03-05 11:40:56 +01:00
$connection = Adminer\connection();
2013-02-22 04:22:02 -08:00
$result = $connection->query('SHOW MASTER STATUS');
if ($result) {
2025-03-05 11:40:56 +01:00
Adminer\restart_session();
2013-02-22 04:22:02 -08:00
$_SESSION["master"] = $result->fetch_assoc();
}
}
}