mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 09:44:55 +02:00
* cache $db->hasTable and $db->hasColumn functions
* changed tableExist and fieldExist to $db->hasTable(table) + $db->hasColumn(table, column) * new configurable: database_log - can log database queries and show in website source when logged as super admin * removed debug_level configurable, enabled by default when logged on super admin * added OTS_Account:getCountry() * added posibility to load OTS_Player partially, and without skills * (internal) changed depracated $ots->createObject() functions with their OTS_ equivalents * (internal) removed unused code
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
class OTS_DB_MySQL extends OTS_Base_DB
|
||||
{
|
||||
private $has_table_cache = array();
|
||||
private $has_column_cache = array();
|
||||
/**
|
||||
* Creates database connection.
|
||||
*
|
||||
@@ -92,9 +94,48 @@ class OTS_DB_MySQL extends OTS_Base_DB
|
||||
$this->prefix = $params['prefix'];
|
||||
}
|
||||
|
||||
if( isset($params['log']) )
|
||||
{
|
||||
$this->logged = true;
|
||||
}
|
||||
|
||||
global $cache, $config;
|
||||
if($cache->enabled()) {
|
||||
$tmp = null;
|
||||
$need_revalidation = true;
|
||||
if($cache->fetch('database_checksum', $tmp) && $tmp) {
|
||||
$tmp = unserialize($tmp);
|
||||
if(sha1($config['database_host'] . '.' . $config['database_name']) == $tmp) {
|
||||
$need_revalidation = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$need_revalidation) {
|
||||
$tmp = null;
|
||||
if($cache->fetch('database_tables', $tmp) && $tmp) {
|
||||
$this->has_table_cache = unserialize($tmp);
|
||||
}
|
||||
|
||||
$tmp = null;
|
||||
if($cache->fetch('database_columns', $tmp) && $tmp) {
|
||||
$this->has_column_cache = unserialize($tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct('mysql:' . implode(';', $dns), $user, $password);
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
global $cache, $config;
|
||||
if($cache->enabled()) {
|
||||
$cache->set('database_tables', serialize($this->has_table_cache));
|
||||
$cache->set('database_columns', serialize($this->has_column_cache));
|
||||
$cache->set('database_checksum', serialize(sha1($config['database_host'] . '.' . $config['database_name'])));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query-quoted field name.
|
||||
*
|
||||
@@ -133,6 +174,23 @@ class OTS_DB_MySQL extends OTS_Base_DB
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function hasTable($name) {
|
||||
if(isset($this->has_table_cache[$name])) {
|
||||
return $this->has_table_cache[$name];
|
||||
}
|
||||
|
||||
global $config;
|
||||
return ($this->has_table_cache[$name] = $this->query("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = " . $this->quote($config['database_name']) . " AND `TABLE_NAME` = " . $this->quote($name) . " LIMIT 1;")->rowCount() > 0);
|
||||
}
|
||||
|
||||
public function hasColumn($table, $column) {
|
||||
if(isset($this->has_column_cache[$table . '.' . $column])) {
|
||||
return $this->has_column_cache[$table . '.' . $column];
|
||||
}
|
||||
|
||||
return ($this->has_column_cache[$table . '.' . $column] = count($this->query("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $column . "'")->fetchAll()) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**#@-*/
|
||||
|
Reference in New Issue
Block a user