本文整理汇总了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;
}
示例2: createStorage
private function createStorage($idSite = null)
{
if (!isset($idSite)) {
$idSite = $this->idSite;
}
return new Storage(Db::get(), $idSite);
}
示例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;
}
示例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;
}
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
}
}
示例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);
}
示例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);
}
示例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;
}