<?php define('EYOUM_EXEC_ROOT', true); require_once 'conf_global.php'; require_once PATH_EYOUM_LIB . 'em_db.class.php'; $db = em_db::singleton(); $select = $db->select()->from(array('a' => 'domain_key'), array('domain_id', 'domain_name'))->join_inner(array('b' => 'domain_basic'), 'a.domain_id=b.domain_id', array('init_time', 'expiration_time'))->where('a.domain_name=\'lb.com\''); print_r($db->fetch_row($select));
protected function getConnection() { if ($this->__debug) { echo __METHOD__ . "\n"; } if (!isset(self::$__is_init)) { $app = new Yaf_Application(PATH_RHEA_ETC . "application.ini", 'rhea'); $app->bootstrap(); self::$__is_init = true; } if (!self::$__conn) { require_once PATH_RHEA_LIB . 'em_db.class.php'; $db = em_db::singleton(); $pdo = $db->get_connection(); self::$__conn = $this->createDefaultDBConnection($pdo, em_config::get('db_name')); } return self::$__conn; }
<?php error_reporting(E_ALL); require_once EMBASE_PATH_EYOU_TOOLMAIL_CONF . 'conf_global.php'; require_once PATH_EYOUM_LIB . 'em_db.class.php'; $opt = ['dbname' => 'test', 'username' => 'root', 'unix_socket' => '/usr/local/eyou/toolmail/run/etm_mysql.sock']; $table = 'post'; $count = 3; $plugin_name = ['p1', 'p2']; $db = em_db::singleton('mysql', $opt); for ($i = 0; $i < $count; $i++) { $time = time() + $i * 300; foreach ($plugin_name as $p) { $ct = $time + mt_rand(1, 100); $param = ['plugin_name' => $p, 'job_time' => $ct, 'title' => $p . '-------' . date('Y-m-d H:i:s', $ct)]; var_dump($p); $db->insert($table, $param); } } $query = $db->select()->from($table); $ret = $db->fetch_all($query); print_r($ret); //explain select c.serial_id, c.plugin_name, c.job_time, c.title from (select plugin_name, max(job_time) as max from postlog group by plugin_name) b inner join postlog c on b.plugin_name = c.plugin_name and b.max = c.job_time;
function get_app($app_name = null, $app_version = null) { $__db = em_db::singleton(); $__db->get_profile()->set_enabled(true); $os_app = new em_os_app(); $app_win = $os_app->get_operator('app_win'); $app_link = $os_app->get_operator('app_link'); $app_action = $os_app->get_operator('app_action'); $condition = em_condition::factory('os:app', 'app:find_app'); $condition->set_prefix(em_os::PREFIX_APP); $condition->set_columns(array('os_app_id')); $condition->set_is_fetch(true); if (isset($app_name)) { $condition->set_eq('app', $app_name); } if (isset($app_version)) { $condition->set_eq('version', $app_version); } $rs = $os_app->find_app($condition); $profile = $__db->get_profile()->get_query_profiles(null, true); var_dump($profile); $is_found = false; while ($row = $rs->fetch()) { $is_found = true; $app = $os_app->get_operator('app')->fetch_app_by_id($row['os_app_id']); foreach ($app['win'] as $win_name => $win_id) { $win = $app_win->fetch_app_win_by_id($row['os_app_id'], $win_id); $app['win'][$win_name] = $win; } foreach ($app['link'] as $link_name => $link_id) { $link = $app_link->fetch_app_link_by_id($row['os_app_id'], $link_id); $app['link'][$link_name] = $link; } foreach ($app['action'] as $action_name => $action_id) { $action = $app_action->fetch_app_action_by_id($row['os_app_id'], $action_id); $app['action'][$action_name] = $action; } //print_r($app); echo PHP_EOL; } if (!$is_found) { error_exit('Not Found.'); } }