当前位置: 首页>>代码示例>>PHP>>正文


PHP DbUtil::getDbNames方法代码示例

本文整理汇总了PHP中DbUtil::getDbNames方法的典型用法代码示例。如果您正苦于以下问题:PHP DbUtil::getDbNames方法的具体用法?PHP DbUtil::getDbNames怎么用?PHP DbUtil::getDbNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbUtil的用法示例。


在下文中一共展示了DbUtil::getDbNames方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: date

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$appId = $_REQUEST['appId'];
$urlId = $_REQUEST['urlId'];
$startDate = $_REQUEST['startDate'];
$endDate = $_REQUEST['endDate'];
if (!$_REQUEST['startDate'] || !$_REQUEST['endDate']) {
    $startDate = $endDate = date('Y-m-d', time() - 86400);
}
$startTime = $startDate . ' 00:00:00';
$endTime = $endDate . ' 23:59:59';
$lastEvenYear = date('Y') % 2 === 0 ? date('Y') : date('Y') - 1;
$lastEvenYearTimestamp = mktime(0, 0, 0, 1, 1, $lastEvenYear);
$startHoursElapsedSinceLastEvenYear = floor((strtotime($startTime) - $lastEvenYearTimestamp) / 3600);
$endHoursElapsedSinceLastEvenYear = floor((strtotime($endTime) - $lastEvenYearTimestamp) / 3600);
$dbNames = DbUtil::getDbNames($appId);
$response = array();
try {
    $sql = 'SELECT ROUND(AVG(avg_network_time), 2) AS networkTime, ROUND(AVG(avg_backend_time), 2) AS backendTime, ROUND(AVG(avg_frontend_time), 2) AS frontendTime, ROUND(AVG(avg_dom_ready_time), 2) AS domReadyTime, ROUND(AVG(avg_done_time), 2) AS doneTime
        FROM ' . $dbNames['summary'] . '.load_time_summary
        WHERE hours_elapsed_since_last_even_year >= :start_hours_elapsed_since_last_even_year
        AND hours_elapsed_since_last_even_year <= :end_hours_elapsed_since_last_even_year
        AND page_id = :page_id';
    $st = $db->prepare($sql);
    $st->bindValue(':start_hours_elapsed_since_last_even_year', $startHoursElapsedSinceLastEvenYear, PDO::PARAM_INT);
    $st->bindValue(':end_hours_elapsed_since_last_even_year', $endHoursElapsedSinceLastEvenYear, PDO::PARAM_INT);
    $st->bindValue(':page_id', $urlId, PDO::PARAM_INT);
    $st->execute();
    $row = $st->fetchAll(PDO::FETCH_ASSOC);
    $response = $row[0];
    $st->closeCursor();
开发者ID:naukri-engineering,项目名称:NewMonk,代码行数:31,代码来源:boomGetBreakupTimes.php

示例2: time

    require_once __DIR__ . '/../config/config.php';
    $lastHourTimestamp = time() - 3600;
    $cronStartTimestamp = strtotime(date('Y-m-d H', $lastHourTimestamp) . ':00:00');
    $cronEndTimestamp = strtotime(date('Y-m-d H', $lastHourTimestamp) . ':59:59');
    $db = ncDatabaseManager::getInstance()->getDatabase('nLogger')->getConnection();
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
    $loggingConfig = ncYaml::load(__DIR__ . '/../config/logging.yml');
    $boomWhitelistedAppIds = $loggingConfig['boomerang'];
    foreach ($boomWhitelistedAppIds['appIds'] as $appId) {
        for ($time = $cronStartTimestamp; $time < $cronEndTimestamp; $time += 3600) {
            $date = date('Y-m-d', $time);
            $hour = date('H', $time);
            $startTime = $date . ' ' . $hour . ':00:00';
            $endTime = $date . ' ' . $hour . ':59:59';
            $dbNames = DbUtil::getDbNames($appId, $date);
            echo 'Processing ' . implode(', ', $dbNames) . ' from ' . $startTime . ' to ' . $endTime . "\n";
            summarizeDb($db, $dbNames, $startTime, $endTime);
            echo "\n----------------\n";
        }
    }
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage() . "<br />\n";
    echo 'Trace: ';
    print_r($e->getTrace());
    echo "<br />\n";
    exit($e->getCode());
}
echo 'Cron ended @ ' . date('Y-m-d H:i:s') . "\n";
function summarizeDb($db, $dbNames, $startTime, $endTime)
{
开发者ID:naukri-engineering,项目名称:NewMonk,代码行数:31,代码来源:boomSummarizeLogs.php

示例3: logBoomr

 public function logBoomr($boomData, $logTime, $ip, $userAgent)
 {
     if ($this->loadTimeOutOfBounds($boomData)) {
         return false;
     }
     $boomData = $this->fixMissingData($boomData);
     if (!$logTime) {
         $logTime = date('Y-m-d H:i:s');
     }
     if (!$ip) {
         $ip = ip2long(\CDNHeaders::getInstance()->getRemoteIP());
     }
     if (!$userAgent) {
         $userAgent = $_SERVER['HTTP_USER_AGENT'];
     }
     $deviceDetails = $this->deviceDetector->getDeviceDetails($userAgent);
     $osName = $deviceDetails['osDetails']["name"] . " " . $deviceDetails['osDetails']["version"];
     $browserName = $deviceDetails['browserDetails']["name"] ? $deviceDetails['browserDetails']["name"] : "Unknown";
     $browserVersion = $deviceDetails['browserDetails']["version"] ? $deviceDetails['browserDetails']["version"] : 0;
     $deviceType = $deviceDetails['type'];
     try {
         $dbNames = \DbUtil::getDbNames($boomData['appId']);
         $db = \ncDatabaseManager::getInstance()->getDatabase('nLogger')->getConnection();
         $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         $db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
         $sql = 'SELECT os_id FROM ' . $dbNames['common'] . '.os WHERE name = :name and device_type = :device_type';
         $st = $db->prepare($sql);
         $st->bindValue(':name', $osName, \PDO::PARAM_STR);
         $st->bindValue(':device_type', $deviceType, \PDO::PARAM_STR);
         $st->execute();
         $result = $st->fetch(\PDO::FETCH_ASSOC);
         $st->closeCursor();
         if ($result['os_id']) {
             $osId = $result['os_id'];
         } else {
             $sql = 'INSERT INTO ' . $dbNames['common'] . '.os (os_id, name,device_type) VALUES(NULL, :name, :device_type)';
             $st = $db->prepare($sql);
             $st->bindValue(':name', $osName, \PDO::PARAM_STR);
             $st->bindValue(':device_type', $deviceType, \PDO::PARAM_STR);
             $st->execute();
             $osId = $db->lastInsertId();
             $st->closeCursor();
         }
         $sql = 'SELECT browser_id FROM ' . $dbNames['common'] . '.browser WHERE name = :name AND version = :version';
         $st = $db->prepare($sql);
         $st->bindValue(':name', $browserName, \PDO::PARAM_STR);
         $st->bindValue(':version', $browserVersion, \PDO::PARAM_STR);
         $st->execute();
         $result = $st->fetch(\PDO::FETCH_ASSOC);
         $st->closeCursor();
         if ($result['browser_id']) {
             $browserId = $result['browser_id'];
         } else {
             $sql = 'INSERT INTO ' . $dbNames['common'] . '.browser (browser_id, name, version) VALUES(NULL, :name, :version)';
             $st = $db->prepare($sql);
             $st->bindValue(':name', $browserName, \PDO::PARAM_STR);
             $st->bindValue(':version', $browserVersion, \PDO::PARAM_STR);
             $st->execute();
             $browserId = $db->lastInsertId();
             $st->closeCursor();
         }
         $sql = 'SELECT env_id FROM ' . $dbNames['main'] . '.env WHERE os_id = :os_id AND browser_id = :browser_id';
         $st = $db->prepare($sql);
         $st->bindValue(':os_id', $osId, \PDO::PARAM_INT);
         $st->bindValue(':browser_id', $browserId, \PDO::PARAM_INT);
         $st->execute();
         $result = $st->fetch(\PDO::FETCH_ASSOC);
         $st->closeCursor();
         if ($result['env_id']) {
             $envId = $result['env_id'];
         } else {
             $sql = 'INSERT INTO ' . $dbNames['main'] . '.env (env_id, os_id, browser_id) VALUES(NULL, :os_id, :browser_id)';
             $st = $db->prepare($sql);
             $st->bindValue(':os_id', $osId, \PDO::PARAM_INT);
             $st->bindValue(':browser_id', $browserId, \PDO::PARAM_INT);
             $st->execute();
             $envId = $db->lastInsertId();
             $st->closeCursor();
         }
         $isUrlATag = !empty($boomData['tag']);
         if ($isUrlATag) {
             $boomData['u'] = $boomData['tag'];
         }
         $urlIds = $this->insertUrl($dbNames, $db, $boomData['u'], $isUrlATag);
         $urlStaticId = $urlIds['urlStaticId'];
         $urlDynamicId = $urlIds['urlDynamicId'];
         $sql = 'SELECT url_id FROM ' . $dbNames['main'] . '.url WHERE url_static_id = :url_static_id AND url_dynamic_id = :url_dynamic_id';
         $st = $db->prepare($sql);
         $st->bindValue(':url_static_id', $urlStaticId, \PDO::PARAM_INT);
         $st->bindValue(':url_dynamic_id', $urlDynamicId, \PDO::PARAM_INT);
         // $st->bindValue(':referrer_static_id', $referrerStaticId, \PDO::PARAM_INT);
         // $st->bindValue(':referrer_dynamic_id', $referrerDynamicId, \PDO::PARAM_INT);
         $st->execute();
         $result = $st->fetch(\PDO::FETCH_ASSOC);
         $st->closeCursor();
         if ($result['url_id']) {
             $urlId = $result['url_id'];
         } else {
             $sql = 'INSERT INTO ' . $dbNames['main'] . '.url (url_id, url_static_id, url_dynamic_id) VALUES(NULL, :url_static_id, :url_dynamic_id)';
             $st = $db->prepare($sql);
//.........这里部分代码省略.........
开发者ID:naukri-engineering,项目名称:NewMonk,代码行数:101,代码来源:Logger.php

示例4: date

<?php

echo 'Cron started @ ' . date('Y-m-d H:i:s') . "\n";
try {
    require_once __DIR__ . '/../config/config.php';
    $tomorrowsDate = date('Y-m-d', time() + 86400);
    $db = ncDatabaseManager::getInstance()->getDatabase('nLogger_cleanup')->getConnection();
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
    $loggingConfig = ncYaml::load(__DIR__ . '/../config/logging.yml');
    $boomWhitelistedAppIds = $loggingConfig['boomerang'];
    foreach ($boomWhitelistedAppIds['appIds'] as $appId) {
        $dbNames = DbUtil::getDbNames($appId, $tomorrowsDate);
        echo 'Processing ' . implode(', ', $dbNames) . ' for ' . $tomorrowsDate . "\n";
        cleanupMainDatabase($db, $dbNames);
        echo "\n----------------\n";
    }
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage() . "<br />\n";
    echo 'Trace: ';
    print_r($e->getTrace());
    echo "<br />\n";
    exit($e->getCode());
}
echo 'Cron ended @ ' . date('Y-m-d H:i:s') . "\n";
function cleanupMainDatabase($db, $dbNames)
{
    $tablesToTruncate = array('bandwidth_latency', 'custom_time', 'env', 'load_time', 'main', 'url', 'url_dynamic', 'url_static');
    foreach ($tablesToTruncate as $tableToTruncate) {
        echo 'Truncating ' . $dbNames['main'] . '.' . $tableToTruncate . "\n";
        $sql = 'TRUNCATE TABLE ' . $dbNames['main'] . '.' . $tableToTruncate;
开发者ID:naukri-engineering,项目名称:NewMonk,代码行数:31,代码来源:boomCleanupLogs.php


注:本文中的DbUtil::getDbNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。