public function db_disconnect() { switch ($this->connect_method) { case "none": $this->db->prefix_changed = 1; $this->db->obj['sql_tbl_prefix'] = ipsRegistry::$settings['sql_tbl_prefix']; if (COLLATE != '' && !empty(ipsRegistry::$settings['sql_charset'])) { $this->db->query("SET NAMES '" . ipsRegistry::$settings['sql_charset'] . "'"); $this->db->query("SET CHARACTER SET '" . ipsRegistry::$settings['sql_charset'] . "'"); } break; case "use": $this->db->query("USE `" . ipsRegistry::$settings['sql_database'] . "`"); $this->db->prefix_changed = 1; $this->db->obj['sql_tbl_prefix'] = ipsRegistry::$settings['sql_tbl_prefix']; if (COLLATE != '' && !empty(ipsRegistry::$settings['sql_charset'])) { $this->db->query("SET NAMES '" . ipsRegistry::$settings['sql_charset'] . "'"); $this->db->query("SET CHARACTER SET '" . ipsRegistry::$settings['sql_charset'] . "'"); } break; default: $this->db->disconnect(); break; } }
function query($sql, $silent = false, $unbuffered = false) { if ($this->slaveid && !$this->slaveexcept && strtoupper(substr($sql, 0, 6)) == 'SELECT') { $this->slave_connect(); } $this->slaveexcept = false; return parent::query($sql, $silent, $unbuffered); }
public function query($sql, $silent = false, $unbuffered = false) { if (!(!$this->slaveexcept && strtoupper(substr($sql, 0, 6)) === 'SELECT' && $this->_slave_connect())) { $this->_master_connect(); } $this->tablename = ''; $this->slaveexcept = false; return parent::query($sql, $silent, $unbuffered); }
/** * Execute a direct database query * * @param string Database query * @param boolean [Optional] Do not convert table prefix * @return @e resource */ public function query($the_query, $bypass = false) { $val = parent::query($the_query, $bypass); if ($this->_isShutDown && in_array(md5($the_query), array_keys($this->_shutDownData))) { $_data = $this->_shutDownData[md5($the_query)]; if ($this->_backup()->isOkToGetThisTableData($_data[1])) { $this->_method = $_data[0]; $this->_table = $_data[1]; } } if ($this->_method) { /* Fetch real insert ID */ $this->_insertId = null; $this->_insertId = $this->getInsertId(); /* Clear method now or it will retain the current table when query log is run below */ $this->_method = ''; /* Do this now if query ran OK */ $this->_backup()->addRawQueryToLog($the_query, $this->_table); } else { if (preg_match('#^(?:insert|update|replace|delete|truncate)#i', $the_query)) { /* Ghetto ->query() method used */ preg_match('#^(TRUNCATE TABLE|DELETE FROM|INSERT INTO|UPDATE|REPLACE INTO)(?:\\s+?)?(\\S+)(\\s+?)?#i', $the_query, $matches); if (count($matches) && !empty($matches[1])) { $this->_method = trim(str_replace(array('table', 'from', 'into'), '', strtolower($matches[1]))); $this->_table = trim($matches[2]); if ($this->_backup()->isOkToGetThisTableData($this->_table)) { /* Fetch real insert ID */ $this->_insertId = null; $this->_insertId = $this->getInsertId(); /* Do this now if query ran OK */ $this->_backup()->addRawQueryToLog($the_query, $this->_table); } } } } $this->_method = ''; $this->_table = ''; return $val; }