diff options
author | Christian Schneider | 2007-02-28 13:28:39 +0000 |
---|---|---|
committer | Christian Schneider | 2007-02-28 13:28:39 +0000 |
commit | b70e73b777bb50be7d8c7a15ca826c1a7826744e (patch) | |
tree | 630d7c596f1ad8c5192d5ee32fc01605ffc47897 | |
parent | 509471eeca48d835f1211a44ad7a2106b4794571 (diff) | |
download | itools-b70e73b777bb50be7d8c7a15ca826c1a7826744e.tar.gz itools-b70e73b777bb50be7d8c7a15ca826c1a7826744e.tar.bz2 itools-b70e73b777bb50be7d8c7a15ca826c1a7826744e.zip |
Implemented server_update parameter to use different host for write operations
-rw-r--r-- | dbi.class | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -20,6 +20,7 @@ class it_dbi ( 'db' => null, 'server' => "localhost", + 'server_update' => null, 'user' => "itools", 'pw' => "24%^jXC~", 'safety' => 1, /* 0= never die, 1=die if query invalid, 2=die also if no results */ @@ -235,6 +236,21 @@ function query($query) $start = gettimeofday(); + if ($this->_server_update && !preg_match('/^(EXPLAIN|SELECT|SHOW) /i', $query)) + { + if ($this->_link = @mysql_connect($this->_server_update, $this->_user, $this->_pw, true)) + { + if (!mysql_select_db($this->_db, $this->_link)) + $this->_fatal("Error selecting update database '$this->_db' on host '$this->_server_update'."); + + $this->_server = $this->_server_update; + unset($this->_server_update); + #it::log('sqllog', "switched to update server $this->_server"); + } + else + $this->_fatal("Error connecting to update database server '$this->_server_update' as user '$this->_user'."); + } + if (!($result = mysql_query($query, $this->_link)) && $this->_safety) { if (($this->_safety < 2) && (mysql_errno($this->_link) == 1062)) /* Duplicate entry */ @@ -275,10 +291,10 @@ function read($id=null) /** * Select a set of records from table and fetch the first one * @param $query Optional array of (field => value) or (int => sqlstring) pairs. Defaults to null (select all records) - * Can contain magic field 'SELECT' for things like 'COUNT(*)' or 'DISTINCT foo', defaults to '*' - * Can contain magic field 'JOIN' for things like 'tableA LEFT JOIN tableB ON a=b', defaults to table name - * If magic field 'CALC_FOUND_ROWS' is true, sets member var _found_rows to number of matching rows without LIMIT - * If magic field 'NOFETCH' is true, then the first row is not prefetched (e.g. when directly using _result) + * Can contain magic field 'SELECT' for things like 'COUNT(*)' or 'DISTINCT foo', defaults to '*' + * Can contain magic field 'JOIN' for things like 'tableA LEFT JOIN tableB ON a=b', defaults to table name + * If magic field 'CALC_FOUND_ROWS' is true, sets member var _found_rows to number of matching rows without LIMIT + * If magic field 'NOFETCH' is true, then the first row is not prefetched (e.g. when directly using _result) * @return Number of matching rows, use iterate() to fetch the next record * @see it_dbi::iterate(), it_db_table::construct_sql_clause() */ |