summaryrefslogtreecommitdiff
path: root/dbi.class
diff options
context:
space:
mode:
Diffstat (limited to 'dbi.class')
-rw-r--r--dbi.class24
1 files changed, 20 insertions, 4 deletions
diff --git a/dbi.class b/dbi.class
index 961cd8f..063c70d 100644
--- a/dbi.class
+++ b/dbi.class
@@ -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()
*/