<?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));
<?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;
<?php define('EYOUM_EXEC_ROOT', true); require_once 'conf_global.php'; require_once PATH_EYOUM_LIB . 'em_db.class.php'; require_once PATH_EYOUM_LIB . 'db/em_db_expr.class.php'; require_once PATH_EYOUM_LIB . 'em_transaction.class.php'; $db = em_db::factory('sqlite', array('dbname' => '/tmp/test.db')); $db->exec('PRAGMA journal_mode=MEMORY;'); $db->exec('PRAGMA synchronous=0;'); $db->exec('PRAGMA cache_size=8000;'); //$table = <<<SQL //CREATE TABLE IF NOT EXISTS test_table ( // rid INTEGER NOT NULL PRIMARY KEY, // cmd_text INTEGER NOT NULL DEFAULT 0 //); //SQL; $db->exec($table); //$trans = new em_transaction(); //$trans->begin(); //$db->query('begin'); //$db->begin_transaction(); //$db->insert('test_table', array('cmd_text' => 2)); $expr = new em_db_expr('cmd_text+1'); $db->update('test_table', array('cmd_text' => '-' . mt_rand()), $db->quote_into('rid = ?', 1)); //$db->rollback(); //$db->commit(); //$db->query('rollback'); //$db->query('commit'); //$trans->rollback(); print_r($db->last_insert_id());
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; }
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.'); } }
<?php error_reporting(E_ALL); require_once 'conf_global.php'; require_once PATH_EYOUM_LIB . 'em_db.class.php'; require_once PATH_EYOUM_LIB . 'db/em_db_expr.class.php'; require_once PATH_EYOUM_LIB . 'em_transaction.class.php'; $opt = array('dbname' => 'eyou_ad_sync', 'username' => 'root', 'unix_socket' => '/usr/local/eyou/mail/run/em_mysql.sock'); $tbl = 'group_sync'; $attr['sync_status'] = new em_db_expr('sync_status+1'); //$attr['sync_status'] = 1; $where = 'domain_name=\'0\' AND group_name=\'0\''; try { $db = em_db::factory(null, $opt); $db->begin_transaction(); $ret = $db->update($tbl, $attr, $where); echo "update result: {$ret}\n"; $query = $db->select()->from($tbl); $data = $db->fetch_all($query); echo "return data: "; print_r(count($data)); sleep(10); $db->commit(); } catch (Exception $e) { echo $e; }