summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2016-06-21 15:11:47 +0200
committerUrban Müller2016-06-21 15:11:47 +0200
commit5330813408668f70db9dcffc9ee6037a58da223e (patch)
tree982cc8a78b5e8129feeae81544c557d28f88fb0b
parent482964d604565ba6aa57552a8bcd6c6d0b4e40e3 (diff)
downloaditools-5330813408668f70db9dcffc9ee6037a58da223e.tar.gz
itools-5330813408668f70db9dcffc9ee6037a58da223e.tar.bz2
itools-5330813408668f70db9dcffc9ee6037a58da223e.zip
warn if writing into replication slave
-rw-r--r--it_dbi.class13
1 files changed, 9 insertions, 4 deletions
diff --git a/it_dbi.class b/it_dbi.class
index d65d1a2..f6614d8 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -454,11 +454,16 @@ function query($query, $p = array())
$p += $this->_p;
$start = gettimeofday(true);
- if ($p['server_update'] && !preg_match('/^(EXPLAIN|SELECT|SHOW) /i', $query))
+ if (!it::match('^(EXPLAIN|SELECT|SHOW)', $query))
{
- debug("switching to update server \"{$p['server_update']}\"", 5);
- $this->_p['server'] = $p['server'] = $p['server_update'];
- unset($this->_p['server_update'], $p['server_update'], $this->_link);
+ if ($p['server_update'])
+ {
+ debug("switching to update server \"{$p['server_update']}\"", 5);
+ $this->_p['server'] = $p['server'] = $p['server_update'];
+ unset($this->_p['server_update'], $p['server_update'], $this->_link);
+ }
+ else if ($p['server'] == "localhost" && ($t = @file($GLOBALS['ULTRAHOME'] . "/doc/machines.txt")) && preg_grep("/^" . gethostname() . "/", array_slice($t, 2)))
+ it::error("local write access on a replication slave machine?");
}
$this->_connect($p); # must be called after update server switching code