public function indexAction() { foreach ($this->app->config['database']['redis'] as $serverId => $server) { if (!empty($server['stats']['enable'])) { $time = time(); $db = Db::factory($server); $info = $db->info(); $statsModel = new Stats_Model($server); $statsModel->addKey('memory', $info['used_memory'], $time); $statsModel->addKey('connections', $info['total_connections_received'], $time); $statsModel->addKey('commands', $info['total_commands_processed'], $time); $statsModel->addKey('expired_keys', $info['expired_keys'], $time); $statsModel->addKey('hits', $info['keyspace_hits'], $time); $statsModel->addKey('misses', $info['keyspace_misses'], $time); $statsModel->addKey('clients', $info['connected_clients'], $time); $statsModel->addKey('user_cpu', $info['used_cpu_user'], $time); $statsModel->addKey('system_cpu', $info['used_cpu_sys'], $time); if ($info['aof_enabled']) { $statsModel->addKey('aof_size', $info['aof_current_size'], $time); $statsModel->addKey('aof_base', $info['aof_base_size'], $time); } foreach ($this->infoModel->getDbs($info) as $i) { if (preg_match('/^keys=([0-9]+),expires=([0-9]+)$/', $info["db{$i}"], $matches)) { $statsModel->addKey("db{$i}:keys", $matches[1], $time); $statsModel->addKey("db{$i}:expired_keys", $matches[2], $time); } } } } }
public function __construct($config) { $this->_objects['app'] = App::instance(); $this->_objects['router'] = Router::instance(); $this->_objects['inputs'] = Inputs::instance(); $this->_objects['session'] = Session::instance(); $this->_objects['log'] = Log::factory(); if (!isset($this->app->config['database']['redis'][$config['serverId']])) { $config['serverId'] = 0; } $current = $this->app->config['database']['redis'][$config['serverId']]; $current['serverId'] = $config['serverId']; $this->_objects['db'] = Db::factory($current); $this->_objects['infoModel'] = new Info_Model($current); $info = $this->db->info(); $dbs = $this->infoModel->getDbs($info); if (!isset($current['max_databases'])) { $databasesConfig = $this->_objects['db']->config('GET', 'databases'); $current['max_databases'] = $databasesConfig['databases']; } // Take care of invalid dbId's. If invalid, set to first available database if (!is_numeric($config['dbId']) || $config['dbId'] < 0 || $config['dbId'] >= $current['max_databases']) { $config['dbId'] = $dbs[0]; } $current['newDB'] = !in_array($config['dbId'], $dbs) ? true : false; $current['database'] = $config['dbId']; // Extract number of keys foreach ($dbs as $i) { if (preg_match('/^keys=([0-9]+),expires=([0-9]+)/', $info["db{$i}"], $matches)) { $current['dbs'][$i] = array('id' => $i, 'keys' => $matches[1], 'name' => isset($current['dbNames'][$i]) ? $current['dbNames'][$i] : null); } } $this->db->select($current['database']); $this->app->current = $current; }
public function __construct($config) { $this->_objects['app'] = App::instance(); $this->_objects['router'] = Router::instance(); $this->_objects['session'] = Session::instance(); $this->_objects['db'] = Db::factory($config); $this->_objects['log'] = Log::factory(); }
/** * Default dispatcher * * @param string $action * @param string $subaction */ public function index($action = '') { template('Install/templates/header')->show('info'); new Menu_Tabs(array('name' => 'install', 'render' => 'content', 'elements' => array(array('label' => t('1. Начало'), 'link' => '', 'active' => check_route('install$')), array('label' => t('2. Проверка'), 'link' => '', 'active' => check_route('check$')), array('label' => t('3. Настройки'), 'link' => '', 'active' => check_route('site$')), array('label' => t('4. Завершение'), 'link' => '', 'active' => check_route('finish$'))))); switch ($action) { case 'check': $tpl = new Template('Install/templates/check'); $tpl->show(); break; case 'site': append('content', '<p class="alert alert-info">' . t('Определите базовые настройки сайта.') . '</p>'); $form = new Form('Install/forms/site'); if ($result = $form->result()) { $site = new Config(SITE . DS . 'site' . EXT); $config = new Config(SITE . DS . 'config' . EXT); $config->site->name = $result->sitename; $site->key or $site->key = md5(md5(time()) + time() + $site->site->name); $result->port or $result->port = 3306; $site->database = array('driver' => config('database.driver'), 'host' => $result->host, 'base' => $result->base, 'user' => $result->user, 'pass' => $result->pass, 'port' => $result->port, 'prefix' => $result->prefix); $db = Db::factory('temp', $site->database); if (!$db->connect()) { if ($result->create_db && $db->connect(FALSE)) { $db->query("CREATE DATABASE `{$site->database->base}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;\n CREATE USER '{$site->database->user}'@'{$site->database->host}' IDENTIFIED BY '{$site->database->pass}';\n GRANT ALL ON `{$site->database->base}`.* TO '{$site->database->user}'@'localhost';\n FLUSH PRIVILEGES;"); } $db->connect(); } if ($db->is_connected) { $site->store(TRUE); $config->store(TRUE); if ($db->import($this->dir . DS . 'cogear.sql', $site->database->prefix)) { redirect(l('/install/finish')); } } else { error(t("Не удалось установить подключение к базе данных."), '', 'content'); } } else { $form->save->label = t('Попробуйте снова'); } $form->show(); break; case 'finish': $tpl = new Template('Install/templates/finish'); $tpl->show(); break; case 'done': // $site = new Config(SITE . DS . 'site' . EXT); // $site->store(TRUE); flash_success(t('Ваш сайт успешно настроен! <p> Данные для входа – логин <b>admin</b> и пароль <b>password</b>.'), '', 'info'); $this->disable(); redirect(); break; default: case 'welcome': $tpl = new Template('Install/templates/welcome'); $tpl->show(); } }
/** * Инициализация */ public function init() { $config = config('database'); $db = Db::factory('system', $config); if ($db->connect()) { parent::init(); $this->object($db); } }
/** * 取得数据库连接实例 * @param string $config 配置 * @return mixed 实例 */ public static function getInstance($config = '') { $guid = toGUIDString($config); if (!isset(self::$_instance[$guid])) { $obj = new Db(); self::$_instance[$guid] = $obj->factory($config); } return self::$_instance[$guid]; }
/** * 取得数据库类实例 * @static * @access public * @return mixed 返回数据库驱动类 */ public static function getInstance($db_config = '') { static $_instance = array(); $guid = to_guid_string($db_config); if (!isset($_instance[$guid])) { $obj = new Db(); $_instance[$guid] = $obj->factory($db_config); } return $_instance[$guid]; }
/** * Constructor * * @param string $tableName Table name to associate with class * @param PDO $db PDO instance * @return void */ public function __construct($tableName = null, $db = null) { if ($db == null) { if (self::$_defaultDb instanceof PDO) { $db = self::$_defaultDb; } else { $db = Db::factory(); } } $this->db = $db; if ($tableName != null) { $this->name = $tableName; } else { if ($this->name == null) { $this->setDefaultTableName(); } } }
/** * 取得数据库类实例 * @static * @access public * @return mixed 返回数据库驱动类 */ public static function getInstance($db_config = '') { static $_instance = array(); $config_str = $db_config; if (is_object($config_str) && function_exists('spl_object_hash')) { $guid = spl_object_hash($config_str); } elseif (is_resource($config_str)) { $config_str = get_resource_type($config_str) . strval($config_str); } else { $config_str = serialize($config_str); } $guid = md5($config_str); if (!isset($_instance[$guid])) { $obj = new Db(); $_instance[$guid] = $obj->factory($db_config); } return $_instance[$guid]; }
public function deleteKeys($job) { $data = unserialize($job->workload()); Log::factory()->write(Log::NOTICE, "Try to delete: {$data['key']} at {$data['server']['host']}:{$data['server']['port']}, DB: {$data['server']['database']}", 'Gearman'); $db = Db::factory($data['server']); $db->changeDB($data['server']['database']); $keys = $db->keys($data['key']); $count = count($keys); if ($count) { $db->set("phpredmin:gearman:deletecount:{$data['key']}", $count); $db->del("phpredmin:gearman:deleted:{$data['key']}"); $db->del("phpredmin:gearman:requests:{$data['key']}"); foreach ($keys as $key) { if ($db->delete($key) !== false) { $db->incrBy("phpredmin:gearman:deleted:{$data['key']}", 1); $db->expireAt("phpredmin:gearman:deleted:{$data['key']}", strtotime('+10 minutes')); } else { Log::factory()->write(Log::INFO, "Unable to delete {$key}", 'Gearman'); } } $db->del("phpredmin:gearman:deletecount:{$data['key']}"); } }
/** * Ejecuta una consulta en el RDBM directamente * * @param string $sql * @return resource */ public static function static_select_one($sql) { $db = Db::factory(); if (substr(ltrim($sql), 0, 7) != "SELECT") { $sql = "SELECT " . $sql; } $num = $db->fetch_one($sql); return $num[0]; }
/** * Constructor * * @return void */ public function __construct() { $this->db = Db::factory(); }
/** * Método que verifica la conexión con la base de datos * @param type $data * @param type $source * @return boolean */ public static function testConnection($data, $source, $db = false) { //Filtro el array con los parámetros $data = Filter::data($data, array('host', 'username', 'password', 'name', 'type'), 'trim'); //Se utiliza por defecto el driver mysqli por ser orientado a objetos $data['type'] = 'mysqli'; $data['charset'] = 'UTF-8'; try { //Seteo las variables del core Config::set("databases.{$source}", $data); //Reviso la conexión, sino, genera la excepción @Db::factory($source, true); MkcMessage::valid("Conexión establecida en modo <b>{$source}!</b>"); } catch (KumbiaException $e) { MkcMessage::error("Error en modo '{$source}': <br /> " . $e->getMessage()); return false; } }
protected function __construct() { $this->db = Db::factory(App::instance()->current); }