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


PHP Db::get方法代码示例

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


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

示例1: tableInsertBatch

 /**
  * Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs,
  * as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs.
  *
  * @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name
  * @param array $fields array of unquoted field names
  * @param array $values array of data to be inserted
  * @param bool $throwException Whether to throw an exception that was caught while trying
  *                                LOAD DATA INFILE, or not.
  * @throws Exception
  * @return bool  True if the bulk LOAD was used, false if we fallback to plain INSERTs
  */
 public static function tableInsertBatch($tableName, $fields, $values, $throwException = false)
 {
     $filePath = StaticContainer::get('path.tmp') . '/assets/' . $tableName . '-' . Common::generateUniqId() . '.csv';
     $loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile'];
     if ($loadDataInfileEnabled && Db::get()->hasBulkLoader()) {
         try {
             $fileSpec = array('delim' => "\t", 'quote' => '"', 'escape' => '\\\\', 'escapespecial_cb' => function ($str) {
                 return str_replace(array(chr(92), chr(34)), array(chr(92) . chr(92), chr(92) . chr(34)), $str);
             }, 'eol' => "\r\n", 'null' => 'NULL');
             // hack for charset mismatch
             if (!DbHelper::isDatabaseConnectionUTF8() && !isset(Config::getInstance()->database['charset'])) {
                 $fileSpec['charset'] = 'latin1';
             }
             self::createCSVFile($filePath, $fileSpec, $values);
             if (!is_readable($filePath)) {
                 throw new Exception("File {$filePath} could not be read.");
             }
             $rc = self::createTableFromCSVFile($tableName, $fields, $filePath, $fileSpec);
             if ($rc) {
                 unlink($filePath);
                 return true;
             }
         } catch (Exception $e) {
             if ($throwException) {
                 throw $e;
             }
         }
     }
     // if all else fails, fallback to a series of INSERTs
     @unlink($filePath);
     self::tableInsertBatchIterate($tableName, $fields, $values);
     return false;
 }
开发者ID:CaptainSharf,项目名称:SSAD_Project,代码行数:45,代码来源:BatchInsert.php

示例2: createStorage

 private function createStorage($idSite = null)
 {
     if (!isset($idSite)) {
         $idSite = $this->idSite;
     }
     return new Storage(Db::get(), $idSite);
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:7,代码来源:StorageTest.php

示例3: tableInsertBatch

 /**
  * Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs,
  * as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs.
  *
  * @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name
  * @param array $fields array of unquoted field names
  * @param array $values array of data to be inserted
  * @param bool $throwException Whether to throw an exception that was caught while trying
  *                                LOAD DATA INFILE, or not.
  * @param string $charset The charset to use, defaults to utf8
  * @throws Exception
  * @return bool  True if the bulk LOAD was used, false if we fallback to plain INSERTs
  */
 public static function tableInsertBatch($tableName, $fields, $values, $throwException = false, $charset = 'utf8')
 {
     $loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile'];
     if ($loadDataInfileEnabled && Db::get()->hasBulkLoader()) {
         $path = self::getBestPathForLoadData();
         $filePath = $path . $tableName . '-' . Common::generateUniqId() . '.csv';
         try {
             $fileSpec = array('delim' => "\t", 'quote' => '"', 'escape' => '\\\\', 'escapespecial_cb' => function ($str) {
                 return str_replace(array(chr(92), chr(34)), array(chr(92) . chr(92), chr(92) . chr(34)), $str);
             }, 'eol' => "\r\n", 'null' => 'NULL', 'charset' => $charset);
             self::createCSVFile($filePath, $fileSpec, $values);
             if (!is_readable($filePath)) {
                 throw new Exception("File {$filePath} could not be read.");
             }
             $rc = self::createTableFromCSVFile($tableName, $fields, $filePath, $fileSpec);
             if ($rc) {
                 unlink($filePath);
                 return true;
             }
         } catch (Exception $e) {
             if ($throwException) {
                 throw $e;
             }
         }
         // if all else fails, fallback to a series of INSERTs
         if (file_exists($filePath)) {
             @unlink($filePath);
         }
     }
     self::tableInsertBatchIterate($tableName, $fields, $values);
     return false;
 }
开发者ID:piwik,项目名称:piwik,代码行数:45,代码来源:BatchInsert.php

示例4: install

    public function install()
    {
        $queries[] = 'CREATE TABLE `' . Common::prefixTable('segment') . '` (
					`idsegment` INT(11) NOT NULL AUTO_INCREMENT,
					`name` VARCHAR(255) NOT NULL,
					`definition` TEXT NOT NULL,
					`login` VARCHAR(100) NOT NULL,
					`enable_all_users` tinyint(4) NOT NULL default 0,
					`enable_only_idsite` INTEGER(11) NULL,
					`auto_archive` tinyint(4) NOT NULL default 0,
					`ts_created` TIMESTAMP NULL,
					`ts_last_edit` TIMESTAMP NULL,
					`deleted` tinyint(4) NOT NULL default 0,
					PRIMARY KEY (`idsegment`)
				) DEFAULT CHARSET=utf8';
        try {
            foreach ($queries as $query) {
                Db::exec($query);
            }
        } catch (Exception $e) {
            if (!Db::get()->isErrNo($e, '1050')) {
                throw $e;
            }
        }
    }
开发者ID:KiwiJuicer,项目名称:handball-dachau,代码行数:25,代码来源:SegmentEditor.php

示例5: migrateConfigSuperUserToDb

 private static function migrateConfigSuperUserToDb()
 {
     $config = Config::getInstance();
     if (!$config->existsLocalConfig()) {
         return;
     }
     try {
         $superUser = $config->superuser;
     } catch (\Exception $e) {
         $superUser = null;
     }
     if (!empty($superUser['bridge']) || empty($superUser) || empty($superUser['login'])) {
         // there is a super user which is not from the config but from the bridge, that means we already have
         // a super user in the database
         return;
     }
     $userApi = UsersManagerApi::getInstance();
     try {
         Db::get()->insert(Common::prefixTable('user'), array('login' => $superUser['login'], 'password' => $superUser['password'], 'alias' => $superUser['login'], 'email' => $superUser['email'], 'token_auth' => $userApi->getTokenAuth($superUser['login'], $superUser['password']), 'date_registered' => Date::now()->getDatetime(), 'superuser_access' => 1));
     } catch (\Exception $e) {
         echo "There was an issue, but we proceed: " . $e->getMessage();
     }
     if (array_key_exists('salt', $superUser)) {
         $salt = $superUser['salt'];
     } else {
         $salt = Common::generateUniqId();
     }
     $config->General['salt'] = $salt;
     $config->superuser = array();
     $config->forceSave();
 }
开发者ID:piwik,项目名称:piwik,代码行数:31,代码来源:2.0.4-b5.php

示例6: initDbIfNeeded

 private function initDbIfNeeded()
 {
     if (!isset($this->db)) {
         // we need to avoid db creation on instance creation, especially important in tracker mode
         // the db might be never actually used when values are eg fetched from a cache
         $this->db = Db::get();
     }
 }
开发者ID:piwik,项目名称:piwik,代码行数:8,代码来源:MeasurableSettingsTable.php

示例7: __construct

 /**
  * @param int $idSite The id of a site. If you want to get settings for a not yet created site just pass an empty value ("0")
  * @param string $idType If no typeId is given, the type of the site will be used.
  *
  * @throws \Exception
  */
 public function __construct($idSite, $idType)
 {
     $this->idSite = $idSite;
     $this->idType = $idType;
     $this->storage = new Storage(Db::get(), $this->idSite);
     $this->pluginName = 'MeasurableSettings';
     $this->init();
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:14,代码来源:MeasurableSettings.php

示例8: test_getUrlToCheckForLatestAvailableVersion

 public function test_getUrlToCheckForLatestAvailableVersion()
 {
     $version = Version::VERSION;
     $phpVersion = urlencode(PHP_VERSION);
     $mysqlVersion = Db::get()->getServerVersion();
     $url = urlencode(Url::getCurrentUrlWithoutQueryString());
     $urlToCheck = $this->channel->getUrlToCheckForLatestAvailableVersion();
     $this->assertStringStartsWith("http://api.piwik.org/1.0/getLatestVersion/?piwik_version={$version}&php_version={$phpVersion}&mysql_version={$mysqlVersion}&release_channel=my_channel&url={$url}&trigger=&timezone=", $urlToCheck);
 }
开发者ID:diosmosis,项目名称:piwik,代码行数:9,代码来源:ReleaseChannelTest.php

示例9: getAllSegmentsForSite

 /**
  * Returns all stored segments that are available for the given site and login.
  *
  * @param  string $userLogin
  * @param  int    $idSite Whether to return stored segments for a specific idSite, or all of them. If supplied, must be a valid site ID.
  * @return array
  */
 public function getAllSegmentsForSite($idSite, $userLogin)
 {
     $bind = array($idSite, $userLogin);
     $sql = $this->buildQuerySortedByName('(enable_only_idsite = ? OR enable_only_idsite = 0)
                                            AND deleted = 0
                                            AND (enable_all_users = 1 OR login = ?)');
     $segments = Db::get()->fetchAll($sql, $bind);
     return $segments;
 }
开发者ID:a4tunado,项目名称:piwik,代码行数:16,代码来源:Model.php

示例10: onSiteDeleted

 public function onSiteDeleted($idSite)
 {
     // we do not delete logs here on purpose (you can run these queries on the log_ tables to delete all data)
     Cache::deleteCacheWebsiteAttributes($idSite);
     $archiveInvalidator = new ArchiveInvalidator();
     $archiveInvalidator->forgetRememberedArchivedReportsToInvalidateForSite($idSite);
     $measurableStorage = new Storage(Db::get(), $idSite);
     $measurableStorage->deleteAllValues();
 }
开发者ID:nuxwin,项目名称:piwik,代码行数:9,代码来源:SitesManager.php

示例11: getUserPasswordMigrations

 /**
  * Returns migrations to hash existing password with bcrypt.
  * @param Migration[] $queries
  * @return Migration[]
  */
 private function getUserPasswordMigrations($queries)
 {
     $db = Db::get();
     $userTable = Common::prefixTable($this->userTable);
     $users = $db->fetchAll('SELECT `login`, `password` FROM `' . $userTable . '` WHERE LENGTH(`password`) = 32');
     foreach ($users as $user) {
         $queries[] = $this->migration->db->boundSql('UPDATE `' . $userTable . '`' . ' SET `password` = ?' . ' WHERE `login` = ?', [password_hash($user['password'], PASSWORD_BCRYPT), $user['login']]);
     }
     return $queries;
 }
开发者ID:piwik,项目名称:piwik,代码行数:15,代码来源:3.0.0-b4.php

示例12: install

 /**
  * Installs the plugin. Derived classes should implement this class if the plugin
  * needs to:
  *
  * - create tables
  * - update existing tables
  * - etc.
  *
  * @throws \Exception if installation of fails for some reason.
  */
 public function install()
 {
     try {
         DbHelper::createTable('bannerstats', "\n            `label` varchar(100) not null,\n            `content_name_id` int not null,\n            `impression`    int not null,\n            `interaction`   int not null,\n            `referrer`      varchar(200),\n            `target`        varchar(200),\n            `date`          date,\n            `custom_var_v1`\tvarchar(200),\n            `custom_var_v2`\tvarchar(200),\n            `custom_var_v3`\tvarchar(200),\n            `custom_var_v4`\tvarchar(200),\n            `custom_var_v5`\tvarchar(200),\n\n            UNIQUE KEY `unique_combination` (`date`, `label`, `content_name_id`, `referrer`, `target`)\n       ");
     } catch (Exception $e) {
         // ignore error if table already exists (1050 code is for 'table already exists')
         if (!Db::get()->isErrNo($e, '1050')) {
             throw $e;
         }
     }
 }
开发者ID:Ratus,项目名称:VPSCashPiwikBannerPlugin,代码行数:21,代码来源:VpsCashPromo.php

示例13: test_SqlMode_IsSet_PDO

 /**
  * @dataProvider getDbAdapter
  */
 public function test_SqlMode_IsSet_PDO($adapter, $expectedClass)
 {
     Db::destroyDatabaseObject();
     Config::getInstance()->database['adapter'] = $adapter;
     $db = Db::get();
     // make sure test is useful and setting adapter works
     $this->assertInstanceOf($expectedClass, $db);
     $result = $db->fetchOne('SELECT @@SESSION.sql_mode');
     $expected = 'NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER';
     $this->assertSame($expected, $result);
 }
开发者ID:normimuc,项目名称:piwik,代码行数:14,代码来源:DbTest.php

示例14: setUp

 public function setUp()
 {
     parent::setUp();
     self::updateDatabase();
     // make sure site has an early enough creation date (for period selector tests)
     Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1");
     $this->addOverlayVisits();
     $this->addNewSitesForSiteSelector();
     DbHelper::createAnonymousUser();
     UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true);
     SitesManagerAPI::getInstance()->updateSite(1, null, null, true);
 }
开发者ID:TensorWrenchOSS,项目名称:piwik,代码行数:12,代码来源:UITestFixture.php

示例15: getMySQLVersion

 public function getMySQLVersion()
 {
     if (isset($this->mySqlCache)) {
         return $this->mySqlCache;
     }
     $this->mySqlCache = '';
     $db = Db::get();
     if (method_exists($db, 'getServerVersion')) {
         $this->mySqlCache = $db->getServerVersion();
     }
     return $this->mySqlCache;
 }
开发者ID:piwik,项目名称:piwik,代码行数:12,代码来源:Environment.php


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