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


PHP Application::getDbConnection方法代码示例

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


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

示例1: getActiveUsersCount

 public static function getActiveUsersCount()
 {
     $sql = "SELECT COUNT(ID) " . "FROM b_user " . "WHERE ACTIVE = 'Y' " . "   AND LAST_LOGIN IS NOT NULL";
     if (ModuleManager::isModuleInstalled("intranet")) {
         $sql = "SELECT COUNT(U.ID) " . "FROM b_user U " . "WHERE U.ACTIVE = 'Y' " . "   AND U.LAST_LOGIN IS NOT NULL " . "   AND EXISTS(" . "       SELECT 'x' " . "       FROM b_utm_user UF, b_user_field F " . "       WHERE F.ENTITY_ID = 'USER' " . "           AND F.FIELD_NAME = 'UF_DEPARTMENT' " . "           AND UF.FIELD_ID = F.ID " . "           AND UF.VALUE_ID = U.ID " . "           AND UF.VALUE_INT IS NOT NULL " . "           AND UF.VALUE_INT <> 0" . "   )";
     }
     $connection = Application::getDbConnection();
     return $connection->queryScalar($sql);
 }
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:9,代码来源:user.php

示例2: getByDomainAndPath

 public static function getByDomainAndPath($domain, $path)
 {
     $connection = Application::getDbConnection();
     $helper = $connection->getSqlHelper();
     $domainForSql = $helper->forSql($domain, 255);
     $pathForSql = $helper->forSql($path);
     $sql = "\n\t\t\tSELECT L.*, L.LID as ID\n\t\t\tFROM b_lang L\n\t\t\t\tLEFT JOIN b_lang_domain LD ON L.LID = LD.LID AND '" . $domainForSql . "' LIKE CONCAT('%', LD.DOMAIN)\n\t\t\tWHERE ('" . $pathForSql . "' LIKE CONCAT(L.DIR, '%') OR LD.LID IS NOT NULL)\n\t\t\t\tAND L.ACTIVE = 'Y'\n\t\t\tORDER BY\n\t\t\t\tIF((L.DOMAIN_LIMITED = 'Y' AND LD.LID IS NOT NULL) OR L.DOMAIN_LIMITED <> 'Y',\n\t\t\t\t\tIF('" . $pathForSql . "' LIKE CONCAT(L.DIR, '%'), 3, 1),\n\t\t\t\t\tIF('" . $pathForSql . "' LIKE CONCAT(L.DIR, '%'), 2, 0)\n\t\t\t\t) DESC,\n\t\t\t\tLENGTH(L.DIR) DESC,\n\t\t\t\tL.DOMAIN_LIMITED DESC,\n\t\t\t\tSORT,\n\t\t\t\tLENGTH(LD.DOMAIN) DESC\n\t\t";
     $siteList = $connection->query($sql);
     return $siteList->fetch();
 }
开发者ID:ASDAFF,项目名称:bitrix-5,代码行数:10,代码来源:site.php

示例3: deleteBySiteId

 public static function deleteBySiteId($siteId)
 {
     if (empty($siteId)) {
         throw new \Bitrix\Main\ArgumentNullException("siteId");
     }
     $result = new \Bitrix\Main\Entity\DeleteResult();
     // event PRE
     // delete
     $connection = \Bitrix\Main\Application::getDbConnection();
     $helper = $connection->getSqlHelper();
     $tableName = static::getEntity()->getDBTableName();
     $sql = "DELETE FROM " . $tableName . " WHERE SITE_ID = '" . $helper->forSql($siteId) . "'";
     $connection->queryExecute($sql);
     // event POST
     return $result;
 }
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:16,代码来源:parameters.php

示例4: getCurrentTemplateId

 public static function getCurrentTemplateId($siteId)
 {
     $cacheFlags = Config\Configuration::getValue("cache_flags");
     $ttl = isset($cacheFlags["site_template"]) ? $cacheFlags["site_template"] : 0;
     $connection = Application::getDbConnection();
     $sqlHelper = $connection->getSqlHelper();
     $field = $connection->getType() === "mysql" ? "`CONDITION`" : "CONDITION";
     $path2templates = IO\Path::combine(Application::getDocumentRoot(), Application::getPersonalRoot(), "templates");
     if ($ttl === false) {
         $sql = "\n\t\t\t\tSELECT " . $field . ", TEMPLATE\n\t\t\t\tFROM b_site_template\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\tORDER BY IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t";
         $recordset = $connection->query($sql);
         while ($record = $recordset->fetch()) {
             $condition = trim($record["CONDITION"]);
             if ($condition != '' && !@eval("return " . $condition . ";")) {
                 continue;
             }
             if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) {
                 return $record["TEMPLATE"];
             }
         }
     } else {
         $managedCache = Application::getInstance()->getManagedCache();
         if ($managedCache->read($ttl, "b_site_template")) {
             $arSiteTemplateBySite = $managedCache->get("b_site_template");
         } else {
             $arSiteTemplateBySite = array();
             $sql = "\n\t\t\t\t\tSELECT " . $field . ", TEMPLATE, SITE_ID\n\t\t\t\t\tFROM b_site_template\n\t\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\t\tORDER BY SITE_ID, IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t\t";
             $recordset = $connection->query($sql);
             while ($record = $recordset->fetch()) {
                 $arSiteTemplateBySite[$record['SITE_ID']][] = $record;
             }
             $managedCache->set("b_site_template", $arSiteTemplateBySite);
         }
         if (is_array($arSiteTemplateBySite[$siteId])) {
             foreach ($arSiteTemplateBySite[$siteId] as $record) {
                 $condition = trim($record["CONDITION"]);
                 if ($condition != '' && !@eval("return " . $condition . ";")) {
                     continue;
                 }
                 if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) {
                     return $record["TEMPLATE"];
                 }
             }
         }
     }
     return ".default";
 }
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:47,代码来源:sitetemplate.php

示例5: delete

 /**
  * Deletes row in entity table by primary key
  *
  * @param string|array $primary
  * @return DeleteResult
  */
 public static function delete($primary)
 {
     // check primary
     static::normalizePrimary($primary);
     static::validatePrimary($primary);
     $entity = static::getEntity();
     $result = new DeleteResult();
     //event before delete
     $event = new DataManagerEvent($entity, "OnBeforeDelete", array("id" => $primary));
     $event->send();
     if ($event->getErrors($result)) {
         return $result;
     }
     //event on delete
     $event = new DataManagerEvent($entity, "OnDelete", array("id" => $primary));
     $event->send();
     // delete
     $connection = Main\Application::getDbConnection();
     $helper = $connection->getSqlHelper();
     $tableName = $entity->getDBTableName();
     $id = array();
     foreach ($primary as $k => $v) {
         $id[] = $k . " = '" . $helper->forSql($v) . "'";
     }
     $where = implode(' AND ', $id);
     $sql = "DELETE FROM " . $tableName . " WHERE " . $where;
     $connection->queryExecute($sql);
     //event after delete
     $event = new DataManagerEvent($entity, "OnAfterDelete", array("id" => $primary));
     $event->send();
     // event POST
     return $result;
 }
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:39,代码来源:datamanager.php

示例6: delete

 public static function delete($moduleId, $name = "", $siteId = "")
 {
     $cacheTtl = self::getCacheTtl();
     if ($cacheTtl !== false) {
         $cache = \Bitrix\Main\Application::getInstance()->getManagedCache();
         $cache->clean("b_option");
     }
     $con = \Bitrix\Main\Application::getDbConnection();
     $sqlHelper = $con->getSqlHelper();
     $strSqlWhere = "";
     if ($name != "") {
         $strSqlWhere .= " AND NAME = '" . $sqlHelper->forSql($name) . "' ";
     }
     if ($siteId != "") {
         $strSqlWhere .= " AND SITE_ID = '" . $sqlHelper->forSql($siteId) . "' ";
     }
     if ($moduleId == "main") {
         $con->queryExecute("DELETE FROM b_option " . "WHERE MODULE_ID = 'main' " . "   AND NAME NOT LIKE '~%' " . "   AND NAME <> 'crc_code' " . "   AND NAME <> 'admin_passwordh' " . "   AND NAME <> 'server_uniq_id' " . "   AND NAME <> 'PARAM_MAX_SITES' " . "   AND NAME <> 'PARAM_MAX_USERS' " . $strSqlWhere);
     } else {
         $con->queryExecute("DELETE FROM b_option " . "WHERE MODULE_ID = '" . $sqlHelper->forSql($moduleId) . "' " . "   AND NAME <> '~bsm_stop_date' " . $strSqlWhere);
     }
     if ($siteId != "") {
         if ($name == "") {
             unset(self::$options[$siteId][$moduleId]);
         } else {
             unset(self::$options[$siteId][$moduleId][$name]);
         }
     } else {
         $arSites = array_keys(self::$options);
         foreach ($arSites as $s) {
             if ($name == "") {
                 unset(self::$options[$s][$moduleId]);
             } else {
                 unset(self::$options[$s][$moduleId][$name]);
             }
         }
     }
 }
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:38,代码来源:option.php

示例7: loadUserSecurityPolicy

 protected function loadUserSecurityPolicy()
 {
     $this->policy = static::$defaultGroupPolicy;
     if ($this->policy["SESSION_TIMEOUT"] <= 0) {
         $this->policy["SESSION_TIMEOUT"] = ini_get("session.gc_maxlifetime") / 60;
     }
     $connection = Main\Application::getDbConnection();
     $sqlHelper = $connection->getSqlHelper();
     $sql = "SELECT G.SECURITY_POLICY " . "FROM b_group G " . "WHERE G.ID = 2 ";
     if ($this->isAuthenticated) {
         $sql .= "UNION " . "SELECT G.SECURITY_POLICY " . "FROM b_group G " . "   INNER JOIN b_user_group UG ON (G.ID = UG.GROUP_ID) " . "WHERE UG.USER_ID = " . intval($this->userId) . " " . "\tAND ((UG.DATE_ACTIVE_FROM IS NULL) OR (UG.DATE_ACTIVE_FROM <= " . $sqlHelper->getCurrentDateTimeFunction() . ")) " . "\tAND ((UG.DATE_ACTIVE_TO IS NULL) OR (UG.DATE_ACTIVE_TO >= " . $sqlHelper->getCurrentDateTimeFunction() . ")) ";
     }
     $recordset = $connection->query($sql);
     while ($record = $recordset->fetch()) {
         if (!empty($record["SECURITY_POLICY"])) {
             $groupPolicy = unserialize($record["SECURITY_POLICY"]);
         } else {
             continue;
         }
         if (!is_array($groupPolicy)) {
             continue;
         }
         foreach ($groupPolicy as $key => $val) {
             switch ($key) {
                 case "STORE_IP_MASK":
                 case "SESSION_IP_MASK":
                     if ($this->policy[$key] < $val) {
                         $this->policy[$key] = $val;
                     }
                     break;
                 case "SESSION_TIMEOUT":
                     if ($this->policy[$key] <= 0 || $this->policy[$key] > $val) {
                         $this->policy[$key] = $val;
                     }
                     break;
                 case "PASSWORD_LENGTH":
                     if ($this->policy[$key] <= 0 || $this->policy[$key] < $val) {
                         $this->policy[$key] = $val;
                     }
                     break;
                 case "PASSWORD_UPPERCASE":
                 case "PASSWORD_LOWERCASE":
                 case "PASSWORD_DIGITS":
                 case "PASSWORD_PUNCTUATION":
                     if ($val === "Y") {
                         $this->policy[$key] = "Y";
                     }
                     break;
                 case "LOGIN_ATTEMPTS":
                     if ($val > 0 && ($this->policy[$key] <= 0 || $this->policy[$key] > $val)) {
                         $this->policy[$key] = $val;
                     }
                     break;
                 default:
                     if ($this->policy[$key] > $val) {
                         $this->policy[$key] = $val;
                     }
             }
         }
     }
     if ($this->policy["PASSWORD_LENGTH"] === false) {
         $this->policy["PASSWORD_LENGTH"] = 6;
     }
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:64,代码来源:currentuser.php

示例8: setAuthentication

 public static function setAuthentication(CurrentUser $user, $isPersistent = false)
 {
     /** @var $context \Bitrix\Main\HttpContext */
     $context = \Bitrix\Main\Application::getInstance()->getContext();
     $context->setUser($user);
     static::copyToSession($user);
     /** @var $response \Bitrix\Main\HttpResponse */
     $response = $context->getResponse();
     if (!$user->isAuthenticated()) {
         $cookie = new \Bitrix\Main\Web\Cookie("UIDH", "", time() - 3600);
         $response->addCookie($cookie);
         return;
     }
     $connection = \Bitrix\Main\Application::getDbConnection();
     $sqlHelper = $connection->getSqlHelper();
     $connection->queryExecute("UPDATE b_user SET " . "   STORED_HASH = NULL, " . "   LAST_LOGIN = " . $sqlHelper->getCurrentDateTimeFunction() . ", " . "   TIMESTAMP_X = TIMESTAMP_X,  " . "   LOGIN_ATTEMPTS = 0, " . "   TIME_ZONE_OFFSET = " . \CTimeZone::getOffset() . " " . "WHERE ID = " . $user->getUserId() . " ");
     $cookie = new \Bitrix\Main\Web\Cookie("LOGIN", $user->getLogin(), time() + 60 * 60 * 24 * 30 * 60);
     $cookie->setSpread(\Bitrix\Main\Config\Option::get("main", "auth_multisite", "N") == "Y" ? \Bitrix\Main\Web\Cookie::SPREAD_SITES : \Bitrix\Main\Web\Cookie::SPREAD_DOMAIN);
     $response->addCookie($cookie);
     if ($isPersistent || \Bitrix\Main\Config\Option::get("main", "auth_multisite", "N") == "Y") {
         $hash = $user->getSessionHash();
         /** @var $request \Bitrix\Main\HttpRequest */
         $request = $context->getRequest();
         if ($isPersistent) {
             $cookie = new \Bitrix\Main\Web\Cookie("UIDH", $hash, time() + 60 * 60 * 24 * 30 * 60);
         } else {
             $cookie = new \Bitrix\Main\Web\Cookie("UIDH", $hash, 0);
         }
         $cookie->setSecure(\Bitrix\Main\Config\Option::get("main", "use_secure_password_cookies", "N") == "Y" && $request->isHttps());
         $response->addCookie($cookie);
         $storedId = static::getStoredHashId($user, $hash);
         if ($storedId) {
             $connection->queryExecute("UPDATE b_user_stored_auth SET " . "\tLAST_AUTH = " . $sqlHelper->getCurrentDateTimeFunction() . ", " . "\t" . ($user->getAuthType() === static::AUTHENTICATED_BY_HASH ? "" : "TEMP_HASH='" . ($isPersistent ? "N" : "Y") . "', ") . " " . "\tIP_ADDR = '" . sprintf("%u", ip2long($request->getRemoteAddress())) . "' " . "WHERE ID = " . intval($storedId));
         } else {
             $sqlTmp1 = "";
             $sqlTmp2 = "";
             if ($connection->getType() === "oracle") {
                 $storedId = $connection->getIdentity("sq_b_user_stored_auth");
                 $sqlTmp1 = "ID, ";
                 $sqlTmp2 = intval($storedId) . ", ";
             }
             $sql = "INSERT INTO b_user_stored_auth (" . $sqlTmp1 . "USER_ID, DATE_REG, LAST_AUTH, TEMP_HASH, " . "   IP_ADDR, STORED_HASH) " . "VALUES (" . $sqlTmp2 . intval($user->getUserId()) . ", " . $sqlHelper->getCurrentDateTimeFunction() . ", " . "   " . $sqlHelper->getCurrentDateTimeFunction() . ", '" . ($isPersistent ? "N" : "Y") . "', " . "   '" . $sqlHelper->forSql(sprintf("%u", ip2long($request->getRemoteAddress()))) . "', " . "   '" . $sqlHelper->forSql($hash) . "')";
             $connection->queryExecute($sql);
             if ($connection->getType() !== "oracle") {
                 $storedId = $connection->getIdentity();
             }
         }
         $user->setStoredAuthId($storedId);
     }
     $event = new Main\Event("main", "OnUserLogin", array("USER" => $user));
     $event->send();
     if (\Bitrix\Main\Config\Option::get("main", "event_log_login_success", "N") === "Y") {
         \CEventLog::log("SECURITY", "USER_AUTHORIZE", "main", $user->getUserId());
     }
 }
开发者ID:Satariall,项目名称:izurit,代码行数:55,代码来源:authentication.php

示例9: clearByTag

 public function clearByTag($tag)
 {
     $con = \Bitrix\Main\Application::getDbConnection();
     $sqlHelper = $con->getSqlHelper();
     if ($tag === true) {
         $sqlWhere = " WHERE TAG <> '*'";
     } else {
         $sqlWhere = "  WHERE TAG = '" . $sqlHelper->forSql($tag) . "'";
     }
     $arDirs = array();
     $rs = $con->query("SELECT * FROM b_cache_tag" . $sqlWhere);
     while ($ar = $rs->fetch()) {
         $arDirs[$ar["RELATIVE_PATH"]] = $ar;
     }
     $con->queryExecute("DELETE FROM b_cache_tag" . $sqlWhere);
     $obCache = Cache::createInstance();
     foreach ($arDirs as $path => $ar) {
         $con->queryExecute("\n\t\t\t\tDELETE FROM b_cache_tag\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($ar["SITE_ID"]) . "'\n\t\t\t\tAND CACHE_SALT = '" . $sqlHelper->forSql($ar["CACHE_SALT"]) . "'\n\t\t\t\tAND RELATIVE_PATH = '" . $sqlHelper->forSql($ar["RELATIVE_PATH"]) . "'\n\t\t\t");
         if (preg_match("/^managed:(.+)\$/", $path, $match)) {
             $this->cleanDir($match[1]);
         } else {
             $obCache->cleanDir($path);
         }
         unset($this->dbCacheTags[$path]);
     }
 }
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:26,代码来源:managedcache.php

示例10: getCookieDomain

 protected function getCookieDomain()
 {
     static $bCache = false;
     static $cache = false;
     if ($bCache) {
         return $cache;
     }
     $context = \Bitrix\Main\Application::getInstance()->getContext();
     $server = $context->getServer();
     $cacheFlags = \Bitrix\Main\Config\Configuration::getValue("cache_flags");
     $cacheTtl = isset($cacheFlags["site_domain"]) ? $cacheFlags["site_domain"] : 0;
     if ($cacheTtl === false) {
         $connection = \Bitrix\Main\Application::getDbConnection();
         $sqlHelper = $connection->getSqlHelper();
         $sql = "SELECT DOMAIN " . "FROM b_lang_domain " . "WHERE '" . $sqlHelper->forSql('.' . $server->getHttpHost()) . "' like " . $sqlHelper->getConcatFunction("'%.'", "DOMAIN") . " " . "ORDER BY " . $sqlHelper->getLengthFunction("DOMAIN") . " ";
         $recordset = $connection->query($sql);
         if ($record = $recordset->fetch()) {
             $cache = $record['DOMAIN'];
         }
     } else {
         $managedCache = \Bitrix\Main\Application::getInstance()->getManagedCache();
         if ($managedCache->read($cacheTtl, "b_lang_domain", "b_lang_domain")) {
             $arLangDomain = $managedCache->get("b_lang_domain");
         } else {
             $arLangDomain = array("DOMAIN" => array(), "LID" => array());
             $connection = \Bitrix\Main\Application::getDbConnection();
             $sqlHelper = $connection->getSqlHelper();
             $recordset = $connection->query("SELECT * " . "FROM b_lang_domain " . "ORDER BY " . $sqlHelper->getLengthFunction("DOMAIN"));
             while ($record = $recordset->fetch()) {
                 $arLangDomain["DOMAIN"][] = $record;
                 $arLangDomain["LID"][$record["LID"]][] = $record;
             }
             $managedCache->set("b_lang_domain", $arLangDomain);
         }
         foreach ($arLangDomain["DOMAIN"] as $domain) {
             if (strcasecmp(substr('.' . $server->getHttpHost(), -(strlen($domain['DOMAIN']) + 1)), "." . $domain['DOMAIN']) == 0) {
                 $cache = $domain['DOMAIN'];
                 break;
             }
         }
     }
     $bCache = true;
     return $cache;
 }
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:44,代码来源:cookie.php


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