public function testRawQueries() { // Insert $inserted = Capsule::insert('INSERT INTO articles (title) VALUES (:title)', ['title' => static::ARTICLE_TITLE]); $this->assertTrue($inserted); // Last Insert ID $id = Capsule::connection()->getPdo()->lastInsertId(); $this->assertEquals(1, $id); // Select $articles = Capsule::select('SELECT * FROM articles WHERE id = ?', [$id]); $this->assertCount(1, $articles); $this->assertEquals($articles[0]->title, static::ARTICLE_TITLE); // Delete $deleted = Capsule::delete('DELETE FROM articles WHERE id = ?', [$id]); $this->assertEquals(1, $deleted); // Count $count = Capsule::selectOne('SELECT COUNT(*) as nb FROM articles'); $this->assertEquals(0, $count->nb); }
/** * 系统信息 - 基本信息 */ public function statistics() { $statistics = array(); /* * 重要: 为了防止与应用别名重名,“服务器信息”、“用户信息”、“开发团队”作为key前面有空格 */ // 服务器信息 //$site_version = model('Xdata')->get('siteopt:site_system_version'); $serverInfo[L('PUBLIC_CORE_VERSION')] = 'TS V' . C('VERSION'); $serverInfo[L('PUBLIC_SERVER_PHP')] = PHP_OS . ' / PHP v' . PHP_VERSION; $serverInfo[L('PUBLIC_SERVER_SOFT')] = $_SERVER['SERVER_SOFTWARE']; $serverInfo[L('PUBLIC_UPLOAD_PERMISSION')] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : '<font color="red">no</font>'; // 数据库信息 $mysqlinfo = Capsule::selectOne('SELECT VERSION() AS version'); $serverInfo[L('PUBLIC_MYSQL')] = $mysqlinfo['version']; $t = D('')->query("SHOW TABLE STATUS LIKE '" . C('DB_PREFIX') . "%'"); $dbsize = 0; foreach ($t as $k) { $dbsize += $k['Data_length'] + $k['Index_length']; } $umap['is_del'] = 0; $userInfo['totalUser'] = model('User')->where($umap)->count(); // 用户总数 $aumap['ctime'] = array('GT', time() - 24 * 3600 * 30); // 1个月内登录过的用户 $userInfo['activeUser'] = D('login_record')->where($aumap)->count(); $ymap['day'] = date('Y-m-d', strtotime('-1 day')); $d = D('online_stats')->where($ymap)->find(); $userInfo['yesterdayUser'] = $d['most_online']; $onmap['uid'] = array('GT', 0); $onmap['activeTime'] = array('GT', time() - 1800); $userInfo['onlineUser'] = count(D()->table(C('DB_PREFIX') . 'online')->where($onmap)->findAll()); $onmap['uid'] = 0; $userInfo['onlineUser'] += count(D()->table(C('DB_PREFIX') . 'online')->where($onmap)->findAll()); // 加上游客 $ymap['day'] = array('GT', date('Y-m-d', strtotime('-7 day'))); $d = D('online_stats')->where($ymap)->field('max(most_online) AS most_online')->find(); $userInfo['weekAvg'] = $d['most_online']; $this->assign('userInfo', $userInfo); $ymap['day'] = array('GT', date('Y-m-d', strtotime('-7 day'))); $d = D('online_stats')->where($ymap)->getHashList('day', '*'); $visitCount = array(); $today = date('Y-m-d'); $yesterday = date('Y-m-d', strtotime('-1 day')); $visitCount['today'] = array('pv' => $d[$today]['total_pageviews'], 'pu' => $d[$today]['total_users'], 'guest' => $d[$today]['total_guests']); $visitCount['yesterday'] = array('pv' => $d[$yesterday]['total_pageviews'], 'pu' => $d[$yesterday]['total_users'], 'guest' => $d[$yesterday]['total_guests']); $apv = 0; $apu = 0; $agu = 0; foreach ($d as $v) { $apv += $v['total_pageviews']; $apu += $v['total_users']; $agu += $v['total_guests']; } $visitCount['weekAvg'] = array('pv' => ceil($apv / count($d)), 'pu' => ceil($apu / count($d)), 'guest' => ceil($agu / count($d))); $this->assign('visitCount', $visitCount); $serverInfo[L('PUBLIC_DATABASE_SIZE')] = byte_format($dbsize); $statistics[L('PUBLIC_SERVER_INFORMATION')] = $serverInfo; unset($serverInfo); // 开发团队 $statistics[L('PUBLIC_DEV_TEAM')] = array(L('PUBLIC_COPYRIGHT') => '<a href="http://www.zhishisoft.com" target="_blank">' . L('PUBLIC_COMPANY') . '</a>'); $this->assign('statistics', $statistics); $this->display(); }