本文整理汇总了PHP中Piwik\Db::fetchOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::fetchOne方法的具体用法?PHP Db::fetchOne怎么用?PHP Db::fetchOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Db
的用法示例。
在下文中一共展示了Db::fetchOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
* Authenticates user
*
* @return AuthResult
*/
public function authenticate()
{
$rootLogin = Config::getInstance()->superuser['login'];
$rootPassword = Config::getInstance()->superuser['password'];
$rootToken = API::getInstance()->getTokenAuth($rootLogin, $rootPassword);
if (is_null($this->login)) {
if ($this->token_auth === $rootToken) {
return new AuthResult(AuthResult::SUCCESS_SUPERUSER_AUTH_CODE, $rootLogin, $this->token_auth);
}
$login = Db::fetchOne('SELECT login
FROM ' . Common::prefixTable('user') . '
WHERE token_auth = ?', array($this->token_auth));
if (!empty($login)) {
return new AuthResult(AuthResult::SUCCESS, $login, $this->token_auth);
}
} else {
if (!empty($this->login)) {
if ($this->login === $rootLogin && $this->getHashTokenAuth($rootLogin, $rootToken) === $this->token_auth || $rootToken === $this->token_auth) {
$this->setTokenAuth($rootToken);
return new AuthResult(AuthResult::SUCCESS_SUPERUSER_AUTH_CODE, $rootLogin, $this->token_auth);
}
$login = $this->login;
$userToken = Db::fetchOne('SELECT token_auth
FROM ' . Common::prefixTable('user') . '
WHERE login = ?', array($login));
if (!empty($userToken) && ($this->getHashTokenAuth($login, $userToken) === $this->token_auth || $userToken === $this->token_auth)) {
$this->setTokenAuth($userToken);
return new AuthResult(AuthResult::SUCCESS, $login, $userToken);
}
}
}
return new AuthResult(AuthResult::FAILURE, $this->login, $this->token_auth);
}
示例2: getIdActionMatchingNameAndType
/**
* @param $name
* @param $type
* @return string
*/
private static function getIdActionMatchingNameAndType($name, $type)
{
$sql = TableLogAction::getSqlSelectActionId();
$bind = array($name, $name, $type);
$idAction = \Piwik\Db::fetchOne($sql, $bind);
return $idAction;
}
示例3: getDbVersion
public static function getDbVersion()
{
$version = Db::fetchOne("SELECT option_value FROM " . Common::prefixTable('option') . " WHERE option_name = ?", array('version_Chat_DB'));
if (!$version) {
$version = Db::tableExists(Common::prefixTable('chat')) === false ? 0 : 1;
}
return $version;
}
示例4: insertVisit
public function insertVisit($visit = array())
{
$defaultProperties = array('idsite' => 1, 'idvisitor' => $this->getDummyVisitorId(), 'visit_last_action_time' => '2012-01-01 00:00:00', 'config_id' => $this->getDummyVisitorId(), 'location_ip' => IPUtils::stringToBinaryIP('1.2.3.4'), 'visitor_localtime' => '2012-01-01 00:00:00', 'location_country' => 'xx', 'config_os' => 'xxx', 'visit_total_events' => 0, 'visitor_days_since_last' => 0, 'config_quicktime' => 0, 'config_pdf' => 0, 'config_realplayer' => 0, 'config_silverlight' => 0, 'config_windowsmedia' => 0, 'config_java' => 0, 'config_gears' => 0, 'config_resolution' => 0, 'config_resolution' => '', 'config_cookie' => 0, 'config_director' => 0, 'config_flash' => 0, 'config_browser_version' => '', 'visitor_count_visits' => 1, 'visitor_returning' => 0, 'visit_total_time' => 123, 'visit_entry_idaction_name' => 0, 'visit_entry_idaction_url' => 0, 'visitor_days_since_order' => 0, 'visitor_days_since_first' => 0, 'visit_first_action_time' => '2012-01-01 00:00:00', 'visit_goal_buyer' => 0, 'visit_goal_converted' => 0, 'visit_exit_idaction_name' => 0, 'referer_url' => '', 'location_browser_lang' => 'xx', 'config_browser_engine' => '', 'config_browser_name' => '', 'referer_type' => 0, 'referer_name' => '', 'visit_total_actions' => 0, 'visit_total_searches' => 0);
$visit = array_merge($defaultProperties, $visit);
$this->insertInto('log_visit', $visit);
$idVisit = Db::fetchOne("SELECT LAST_INSERT_ID()");
return $this->getVisit($idVisit, $allColumns = true);
}
示例5: getAverageVisitTimeData
public function getAverageVisitTimeData($idSite, $lastMinutes = 30, $lastDays = 30)
{
\Piwik\Piwik::checkUserHasViewAccess($idSite);
$lastMinutes = (int) $lastMinutes;
$lastDays = (int) $lastDays;
/* Time is UTC in database. */
$refNow = Date::factory('now');
$timeLimit = $refNow->subDay($lastDays)->toString('Y-m-d H:i:s');
$sql = "SELECT MAX(g.average_time) AS maxtime\n FROM (\n SELECT AVG(visit_total_time) as average_time\n FROM " . \Piwik\Common::prefixTable("log_visit") . "\n WHERE visit_last_action_time >= ?\n AND idsite = ?\n GROUP BY round(UNIX_TIMESTAMP(visit_last_action_time) / ?)\n ) g";
$maxtime = \Piwik\Db::fetchOne($sql, array($timeLimit, $idSite, $lastMinutes * 60));
$timeLimit = $refNow->subHour($lastMinutes / 60)->toString('Y-m-d H:i:s');
$sql = "SELECT AVG(visit_total_time)\n FROM " . \Piwik\Common::prefixTable("log_visit") . "\n WHERE idsite = ?\n AND visit_last_action_time >= ?";
$average_time = \Piwik\Db::fetchOne($sql, array($idSite, $timeLimit));
return array('maxtime' => (int) $maxtime, 'average_time' => (int) $average_time);
}
示例6: performSetUp
public function performSetUp($setupEnvironmentOnly = false)
{
parent::performSetUp($setupEnvironmentOnly);
$this->createSegments();
$this->setupDashboards();
$visitorIdDeterministic = bin2hex(Db::fetchOne("SELECT idvisitor FROM " . Common::prefixTable('log_visit') . " WHERE idsite = 2 AND location_latitude IS NOT NULL LIMIT 1"));
$this->testEnvironment->forcedIdVisitor = $visitorIdDeterministic;
$this->testEnvironment->overlayUrl = $this->getLocalTestSiteUrl();
$this->createOverlayTestSite();
$forcedNowTimestamp = Option::get("Tests.forcedNowTimestamp");
if ($forcedNowTimestamp == false) {
throw new Exception("Incorrect fixture setup, Tests.forcedNowTimestamp option does not exist! Run the setup again.");
}
$this->testEnvironment->forcedNowTimestamp = $forcedNowTimestamp;
$this->testEnvironment->save();
}
示例7: getSql
public static function getSql()
{
$result = array('ALTER TABLE ' . Common::prefixTable('logger_message') . ' MODIFY level VARCHAR(16) NULL' => false);
$unneededLogTables = array('logger_exception', 'logger_error', 'logger_api_call');
foreach ($unneededLogTables as $table) {
$tableName = Common::prefixTable($table);
try {
$rows = Db::fetchOne("SELECT COUNT(*) FROM {$tableName}");
if ($rows == 0) {
$result["DROP TABLE {$tableName}"] = false;
}
} catch (\Exception $ex) {
// ignore
}
}
return $result;
}
示例8: getMigrations
public function getMigrations(Updater $updater)
{
$result = array($this->migration->db->sql('ALTER TABLE ' . Common::prefixTable('logger_message') . ' MODIFY level VARCHAR(16) NULL'));
$unneededLogTables = array('logger_exception', 'logger_error', 'logger_api_call');
foreach ($unneededLogTables as $table) {
$tableName = Common::prefixTable($table);
try {
$rows = Db::fetchOne("SELECT COUNT(*) FROM {$tableName}");
if ($rows == 0) {
$result[] = $this->migration->db->dropTable($table);
}
} catch (\Exception $ex) {
// ignore
}
}
return $result;
}
示例9: addArchivingIdMigrationQueries
private function addArchivingIdMigrationQueries($sql)
{
$tables = ArchiveTableCreator::getTablesArchivesInstalled();
foreach ($tables as $table) {
$type = ArchiveTableCreator::getTypeFromTableName($table);
if ($type === ArchiveTableCreator::NUMERIC_TABLE) {
$maxId = Db::fetchOne('SELECT MAX(idarchive) FROM ' . $table);
if (!empty($maxId)) {
$maxId = (int) $maxId + 500;
} else {
$maxId = 1;
}
$sql[] = $this->migration->db->insert($this->sequenceTable, array('name' => $table, 'value' => $maxId));
}
}
return $sql;
}
示例10: addArchivingIdMigrationQueries
private static function addArchivingIdMigrationQueries($sql)
{
$tables = ArchiveTableCreator::getTablesArchivesInstalled();
foreach ($tables as $table) {
$type = ArchiveTableCreator::getTypeFromTableName($table);
if ($type === ArchiveTableCreator::NUMERIC_TABLE) {
$maxId = Db::fetchOne('SELECT MAX(idarchive) FROM ' . $table);
if (!empty($maxId)) {
$maxId = (int) $maxId + 500;
} else {
$maxId = 1;
}
$query = self::getQueryToCreateSequence($table, $maxId);
// refs #6696, ignores Integrity constraint violation: 1062 Duplicate entry 'piwik_archive_numeric_2010_01' for key 'PRIMARY'
$sql[$query] = '1062';
}
}
return $sql;
}
示例11: performSetUp
public function performSetUp($setupEnvironmentOnly = false)
{
$this->extraTestEnvVars = array('loadRealTranslations' => 1);
parent::performSetUp($setupEnvironmentOnly);
$this->createSegments();
$this->setupDashboards();
$visitorIdDeterministic = bin2hex(Db::fetchOne("SELECT idvisitor FROM " . Common::prefixTable('log_visit') . " WHERE idsite = 2 AND location_latitude IS NOT NULL LIMIT 1"));
$this->testEnvironment->forcedIdVisitor = $visitorIdDeterministic;
$this->testEnvironment->overlayUrl = $this->getLocalTestSiteUrl();
$this->createOverlayTestSite();
$forcedNowTimestamp = Option::get("Tests.forcedNowTimestamp");
if ($forcedNowTimestamp == false) {
throw new Exception("Incorrect fixture setup, Tests.forcedNowTimestamp option does not exist! Run the setup again.");
}
$this->testEnvironment->forcedNowTimestamp = $forcedNowTimestamp;
$this->testEnvironment->save();
// launch archiving so tests don't run out of time
print "Archiving in fixture set up...";
VisitsSummaryAPI::getInstance()->get('all', 'year', '2012-08-09');
VisitsSummaryAPI::getInstance()->get('all', 'year', '2012-08-09', urlencode(OmniFixture::DEFAULT_SEGMENT));
print "Done.";
}
示例12: bannerStats
private function bannerStats($bannerName, $params)
{
$contentPiece = false;
if (strpos($bannerName, '_') !== false) {
list($bannerName, $contentPiece) = explode('_', $bannerName);
}
$segment = 'contentName==' . $bannerName;
$recordName = Dimensions::getRecordNameForAction('getContentPieces');
$subTable = Archive::getDataTableFromArchive($recordName, $params['idSite'], $params['period'], $params['date'], $segment, true);
//echo '<pre>';
$bannerTable = new DataTable();
if (!$contentPiece) {
foreach ($subTable->getRows() as $row) {
$ContentPieceId = Db::fetchOne("SELECT idaction FROM piwik_log_action WHERE TYPE = 14 and name = ?", array($row->getColumn('label')));
$bannerRow = new Row(array(Row::COLUMNS => array('Label' => $row->getColumn('label'), 'Impressions' => $row->getColumn(41), 'Interactions' => $row->getColumn(42), 'Conversion rate' => $this->interactionRate($row->getColumn(41), $row->getColumn(42))), Row::DATATABLE_ASSOCIATED => implode('_', array($bannerName, $ContentPieceId))));
$bannerTable->addRow($bannerRow);
}
} else {
$orderColumn = str_replace(' ', '_', strtolower($params['filter_sort_column']));
$orderOrder = in_array($params['filter_sort_order'], array('asc', 'desc')) ? $params['filter_sort_order'] : 'asc';
$orderLimit = intval($params['filter_limit']);
$where = '';
/*
TODO: filter_pattern is processed by piwik in some way. The results are good with this query, but piwik does some post-processing?
if (isset($params['filter_pattern'])) {
$where = 'and piwik_log_action.name like "%' . $params['filter_pattern'] . '%"';
}
*/
$result = Db::fetchAll("\n SELECT \n trim(substring_index(piwik_log_action.name, '|', 1)) as referrer,\n trim(substring_index(piwik_log_action.name, '|', -1)) as target,\n sum(IF(idaction_content_interaction is null, 1, 0)) as impressions, \n sum(IF(idaction_content_interaction is null, 0, 1)) as interactions,\n ((100 / sum(IF(idaction_content_interaction is null, 1, 0))) * sum(IF(idaction_content_interaction is null, 0, 1))) as conversion_rate\n FROM piwik_log_link_visit_action \n left join piwik_log_action on piwik_log_action.idaction = idaction_content_target\n WHERE \n idaction_content_name in (SELECT idaction FROM piwik_log_action WHERE name = ?)\n and\n idaction_content_piece = ?\n \n {$where}\n\n group by piwik_log_action.name\n order by {$orderColumn} {$orderOrder}\n limit {$orderLimit}\n ", array($bannerName, $contentPiece));
foreach ($result as $row) {
$bannerRow = new Row(array(Row::COLUMNS => array('Referrer' => $row['referrer'], 'Target' => $row['target'], 'Impressions' => $row['impressions'], 'Interactions' => $row['interactions'], 'Conversion rate' => round($row['conversion_rate']) . '%')));
$bannerTable->addRow($bannerRow);
}
}
return $bannerTable;
}
示例13: getArchiveRowCountWithId
private function getArchiveRowCountWithId($table, $archiveIds)
{
return Db::fetchOne("SELECT COUNT(*) FROM {$table} WHERE idarchive IN (" . implode(',', $archiveIds) . ")");
}
示例14: getMaxGoalId
private static function getMaxGoalId()
{
return Db::fetchOne("SELECT MAX(idgoal) FROM " . Common::prefixTable('goal'));
}
示例15: insertActionsToKeep
protected function insertActionsToKeep($maxIds, $olderThan = true, $insertIntoTempIterationStep = 100000)
{
$tempTableName = Common::prefixTable(self::DELETE_UNUSED_ACTIONS_TEMP_TABLE_NAME);
$idColumns = $this->getTableIdColumns();
foreach ($this->dimensionMetadataProvider->getActionReferenceColumnsByTable() as $table => $columns) {
$idCol = $idColumns[$table];
foreach ($columns as $col) {
$select = "SELECT {$col} FROM " . Common::prefixTable($table) . " WHERE {$idCol} >= ? AND {$idCol} < ?";
$sql = "INSERT IGNORE INTO {$tempTableName} {$select}";
if ($olderThan) {
$start = 0;
$finish = $maxIds[$table];
} else {
$start = $maxIds[$table];
$finish = Db::fetchOne("SELECT MAX({$idCol}) FROM " . Common::prefixTable($table));
}
Db::segmentedQuery($sql, $start, $finish, $insertIntoTempIterationStep);
}
}
}