diff options
Diffstat (limited to 'it_dbi.class')
-rw-r--r-- | it_dbi.class | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/it_dbi.class b/it_dbi.class index 79c3e03..f59d779 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -21,7 +21,7 @@ class it_dbi { - static $singleton; + static $_global_key = 'it_dbi'; # $GLOBAL key to use for singleton var $_found_rows; # public: number of found rows if CALC_FOUND_ROWS was set var $_data; # semi-public: current result as assoc array @@ -71,7 +71,7 @@ function __construct($p = array(), $query = null) $p['db'] = strtr(it::match('/www/([^/]*)', $p['home']), '.-', '__'); # If the global singleton defaults are for this db/server/server_update then use them. - $dp = (array)static::$singleton->_p; + $dp = (array)$GLOBALS[static::$_global_key]->_p; if ((!isset($p['db']) || ($p['db'] == $dp['db'])) && (!isset($p['server']) || ($p['server'] == $dp['server'])) && (!isset($p['server_update']) || ($p['server_update'] == $dp['server_update']))) $p += $dp; @@ -83,8 +83,8 @@ function __construct($p = array(), $query = null) if ($p['table']) # Standard use: create a table object { - if (!isset(static::$singleton)) - new static; + if (!isset($GLOBALS[static::$_global_key])) + new static::$_global_key; if ($p['getfieldinfo']) $this->_p += $this->_get_field_info(); # Get $this->_fields and p[keyfield, autoincrement, randomid] @@ -100,7 +100,7 @@ function __construct($p = array(), $query = null) $this->read($query); } else - static::$singleton =& $this; + $GLOBALS[static::$_global_key] =& $this; } /** @@ -117,7 +117,7 @@ function __construct($p = array(), $query = null) static function createclasses($p = array()) { # Make sure singleton exists - $dbi = static::$singleton ?: new static($p); + $dbi = $GLOBALS[static::$_global_key] ?: new static::$_global_key($p); $p += $dbi->_p; @@ -151,7 +151,7 @@ static function createclass($p) $p = array('table' => $p); # Make sure singleton exists - $dbi = static::$singleton ?: new static(['table' => null] + $p); + $dbi = $GLOBALS[static::$_global_key] ?: new static::$_global_key(['table' => null] + $p); $p += $dbi->_p; # FIXME: (has to be checked for side effects!) $dbid = $dbi->_dbid = "{$p['user']}@{$p['server']}:{$p['db']}"; @@ -214,7 +214,7 @@ function _connect($p = array()) if ($p['reconnect'] || !($this->_link = $state['link'])) { # Force new link if same server/user was seen before (mysql ignores selected db) - if (static::$singleton->_connected["{$p['server']}/{$p['user']}"]++) + if ($GLOBALS[static::$_global_key]->_connected["{$p['server']}/{$p['user']}"]++) list($this->_link, $error) = $this->_connect_db($p); else list($this->_link, $error) = $this->_connect_db($p); @@ -969,14 +969,14 @@ function _get_field_info() } } - unset(static::$singleton->_p['table'], static::$singleton->_p['keyfield']); # Remove cruft + unset($GLOBALS[static::$_global_key]->_p['table'], $GLOBALS[static::$_global_key]->_p['keyfield']); # Remove cruft return $result; } static function _state_get($dbid) { - if (!($result = static::$singleton->_state[$dbid])) - $result = static::$singleton->_state[$dbid] = (array)it_cache::get(get_called_class() . ":$dbid"); + if (!($result = $GLOBALS[static::$_global_key]->_state[$dbid])) + $result = $GLOBALS[static::$_global_key]->_state[$dbid] = (array)it_cache::get(get_called_class() . ":$dbid"); #var_dump("get", $dbid, $result); return $result; @@ -985,7 +985,7 @@ static function _state_get($dbid) static function _state_put($dbid, $state, $shared = true) { #var_dump("put", $dbid, $state); - static::$singleton->_state[$dbid] = $state; + $GLOBALS[static::$_global_key]->_state[$dbid] = $state; if ($shared) it_cache::put(get_called_class() . ":$dbid", array('link' => null) + (array)$state); # link is not transferable } @@ -993,7 +993,7 @@ static function _state_put($dbid, $state, $shared = true) static function _state_purgeshared($dbid = null) { #var_dump("purgeshared", $dbid); - it_cache::put(get_called_class(). ":" . ($dbid ? $dbid : static::$singleton->_dbid), array()); # Nuke shared cache + it_cache::put(get_called_class(). ":" . ($dbid ? $dbid : $GLOBALS[static::$_global_key]->_dbid), array()); # Nuke shared cache } # |