本文整理汇总了PHP中Bitrix\Main\HttpApplication::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpApplication::getConnection方法的具体用法?PHP HttpApplication::getConnection怎么用?PHP HttpApplication::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitrix\Main\HttpApplication
的用法示例。
在下文中一共展示了HttpApplication::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
public static function search($words)
{
$dbConnection = Main\HttpApplication::getConnection();
$dbHelper = Main\HttpApplication::getConnection()->getSqlHelper();
$wordStatTableName = WordStatTable::getTableName();
$preparedLike = array();
foreach ($words as $word) {
$preparedLike[] = "%TABLE_NAME%.WORD like '" . $dbHelper->forSql($word) . "%'";
}
$preparedLike = implode(' or ', $preparedLike);
$sql = "\n\t\t\tselect C.*, WS_CITY.WORD as CWORD, WS_VILLAGE.WORD as VWORD, WS_STREET.WORD as SWORD from " . static::getTableName() . " C\n\n\t\t\t\tinner join b_sale_loc_word_stat WS_STREET on \n\n\t\t\t\t\t(\n\t\t\t\t\t\tWS_STREET.TYPE_ID = '7'\n\t\t\t\t\t\tand\n\t\t\t\t\t\tWS_STREET.LOCATION_ID = C.STREET_ID\n\t\t\t\t\t\tand\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t(" . str_replace(array('%TABLE_NAME%'), array('WS_STREET'), $preparedLike) . ")\n\t\t\t\t\t\t\tor\n\t\t\t\t\t\t\t(WS_STREET.LOCATION_ID = '0')\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\n\t\t\t\tinner join b_sale_loc_word_stat WS_VILLAGE on \n\n\t\t\t\t\t(\n\t\t\t\t\t\tWS_VILLAGE.TYPE_ID = '6'\n\t\t\t\t\t\tand\n\t\t\t\t\t\tWS_VILLAGE.LOCATION_ID = C.VILLAGE_ID\n\t\t\t\t\t\tand\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t(" . str_replace(array('%TABLE_NAME%'), array('WS_VILLAGE'), $preparedLike) . ")\n\t\t\t\t\t\t\tor\n\t\t\t\t\t\t\t(WS_VILLAGE.LOCATION_ID = '0')\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\n\t\t\t\tinner join b_sale_loc_word_stat WS_CITY on \n\n\t\t\t\t\t(\n\t\t\t\t\t\tWS_CITY.TYPE_ID = '3'\n\t\t\t\t\t\tand\n\t\t\t\t\t\tWS_CITY.LOCATION_ID = C.CITY_ID\n\t\t\t\t\t\tand\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t(" . str_replace(array('%TABLE_NAME%'), array('WS_CITY'), $preparedLike) . ")\n\t\t\t\t\t\t\tor\n\t\t\t\t\t\t\t(WS_CITY.LOCATION_ID = '0')\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\n\t\t\torder by C.TYPE_SORT desc\n\t\t\tlimit 5\n\t\t";
/*
$sql = "
select * from ".static::getTableName()." C
where
(
C.CITY_ID = 0 or C.CITY_ID in (
select LOCATION_ID from b_sale_loc_word_stat
where
TYPE_ID = 3
and
(".$preparedLike.")
)
)
and
(
C.VILLAGE_ID = 0 or C.VILLAGE_ID in (
select LOCATION_ID from b_sale_loc_word_stat
where
TYPE_ID = 6
and
(".$preparedLike.")
)
)
and
(
C.STREET_ID = 0 or C.STREET_ID in (
select LOCATION_ID from b_sale_loc_word_stat
where
TYPE_ID = 7
and
(".$preparedLike.")
)
)
order by C.TYPE_SORT desc
limit 5
";
*/
print '<pre>';
print_r($sql);
print '</pre>';
return $dbConnection->query($sql);
}
示例2: initializeData
public static function initializeData()
{
$locationTable = Location\LocationTable::getTableName();
$groupLocationTable = Location\GroupLocationTable::getTableName();
$siteLocationTable = Location\SiteLocationTable::getTableName();
// ORACLE: OK, MSSQL: OK
$sql = "\n\t\t\tinsert into " . static::getTableName() . " \n\t\t\t\t(LOCATION_ID, SITE_ID) \n\t\t\tselect LC.ID, LS.SITE_ID\n\t\t\t\tfrom " . $siteLocationTable . " LS\n\t\t\t\t\tinner join " . $locationTable . " L on LS.LOCATION_ID = L.ID and LS.LOCATION_TYPE = 'L'\n\t\t\t\t\tinner join " . $locationTable . " LC on LC.LEFT_MARGIN >= L.LEFT_MARGIN and LC.RIGHT_MARGIN <= L.RIGHT_MARGIN\n\t\t\tunion \n\t\t\tselect LC.ID, LS.SITE_ID\n\t\t\t\tfrom " . $siteLocationTable . " LS\n\t\t\t\t\tinner join " . $groupLocationTable . " LG on LS.LOCATION_ID = LG.LOCATION_GROUP_ID and LS.LOCATION_TYPE = 'G'\n\t\t\t\t\tinner join " . $locationTable . " L on LG.LOCATION_ID = L.ID\n\t\t\t\t\tinner join " . $locationTable . " LC on LC.LEFT_MARGIN >= L.LEFT_MARGIN and LC.RIGHT_MARGIN <= L.RIGHT_MARGIN\n\t\t";
Main\HttpApplication::getConnection()->query($sql);
}
示例3: addPropertyValueField
protected static function addPropertyValueField($tableAlias = 'V', &$arFields, &$arSelectFields)
{
$tableAlias = \Bitrix\Main\HttpApplication::getConnection()->getSqlHelper()->forSql($tableAlias);
// locations kept in CODEs, but must be shown as IDs
if (CSaleLocation::isLocationProMigrated()) {
$arSelectFields = array_merge(array('PROP_TYPE'), $arSelectFields);
// P.TYPE should be there and go above our join
$arFields['VALUE'] = array("FIELD" => "\n\t\t\t\tCASE\n\n\t\t\t\t\tWHEN\n\t\t\t\t\t\tP.TYPE = 'LOCATION'\n\t\t\t\t\tTHEN\n\t\t\t\t\t\tCAST(L.ID as " . \Bitrix\Sale\Location\DB\Helper::getSqlForDataType('char', 255) . ")\n\n\t\t\t\t\tELSE\n\t\t\t\t\t\t" . $tableAlias . ".VALUE\n\t\t\t\tEND\n\t\t\t", "TYPE" => "string", "FROM" => "LEFT JOIN b_sale_location L ON (P.TYPE = 'LOCATION' AND " . $tableAlias . ".VALUE IS NOT NULL AND " . $tableAlias . ".VALUE = L.CODE)");
$arFields['VALUE_ORIG'] = array("FIELD" => $tableAlias . ".VALUE", "TYPE" => "string");
} else {
$arFields['VALUE'] = array("FIELD" => $tableAlias . ".VALUE", "TYPE" => "string");
}
}
示例4: dropIndexByName
public static function dropIndexByName($indexName, $tableName)
{
$dbConnection = Main\HttpApplication::getConnection();
$dbHelper = $dbConnection->getSqlHelper();
$indexName = $dbHelper->forSql(trim($indexName));
$tableName = $dbHelper->forSql(trim($tableName));
if (!strlen($indexName) || !strlen($tableName)) {
return false;
}
if (!static::checkIndexNameExists($indexName, $tableName)) {
return false;
}
$dbConnection->query("drop index {$indexName} on {$tableName}");
return true;
}
示例5: stageRebalanceWalkTree
protected function stageRebalanceWalkTree()
{
if (!isset($this->data['rebalance']['queue'])) {
$this->restoreIndexes('IX_B_SALE_LOC_PARENT');
$this->logMessage('initialize Queue');
$this->data['rebalance']['margin'] = -1;
$this->data['processed'] = 0;
$this->data['rebalance']['queue'] = array(array('I' => 'root', 'D' => 0));
$tableName = Location\LocationTable::getTableName();
$res = Main\HttpApplication::getConnection()->query("select count(*) as CNT from {$tableName}")->fetch();
$this->data['rebalance']['cnt'] = intval($res['CNT']);
}
$i = -1;
while (!empty($this->data['rebalance']['queue']) && $this->checkQuota()) {
$i++;
$node =& $this->data['rebalance']['queue'][0];
if (isset($node['L'])) {
// we have already been here
array_shift($this->data['rebalance']['queue']);
if ($node['I'] != 'root') {
$this->acceptRebalancedNode(array('I' => $node['I'], 'D' => $node['D'], 'L' => $node['L'], 'R' => ++$this->data['rebalance']['margin']));
} else {
$this->data['rebalance']['margin']++;
}
} else {
$a = $this->getCachedBundle($node['I']);
if (!empty($a)) {
// go deeper
$node['L'] = ++$this->data['rebalance']['margin'];
foreach ($a as $id) {
if ($this->checkNodeIsParent($id)) {
array_unshift($this->data['rebalance']['queue'], array('I' => $id, 'D' => $node['D'] + 1));
} else {
$this->acceptRebalancedNode(array('I' => $id, 'D' => $node['D'] + 1, 'L' => ++$this->data['rebalance']['margin'], 'R' => ++$this->data['rebalance']['margin']));
}
}
} else {
array_shift($this->data['rebalance']['queue']);
$this->acceptRebalancedNode(array('I' => $node['I'], 'D' => $node['D'], 'L' => ++$this->data['rebalance']['margin'], 'R' => ++$this->data['rebalance']['margin']));
}
}
}
$this->logMessage('Q size is ' . count($this->data['rebalance']['queue']) . ' already processed: ' . $this->data['processed'] . '/' . $this->data['rebalance']['cnt']);
$this->logMemoryUsage();
if (empty($this->data['rebalance']['queue'])) {
// last flush & then merge
$this->mergeRebalancedNodes();
$this->nextStage();
return;
}
$this->rebalanceInserter->flush();
$this->nextStep();
}
示例6: checkLinkExists
public static function checkLinkExists($id, $parentId, array $parameters = array('BIDIRECTIONAL' => false))
{
$parentColName = static::getPARENTIDColumnName();
$idColName = static::getIDColumnName();
//$directColName = static::getDIRECTColumnName();
$id = intval($id);
$parentId = intval($parentId);
if (!$id || !$parentId) {
return false;
// link to non-existed nodes does not exist
}
$item = HttpApplication::getConnection()->query("\n\t\t\tselect " . $idColName . " \n\t\t\t\tfrom \n\t\t\t\t\t" . static::getTableName() . " \n\t\t\t\twhere \n\t\t\t\t\t(\n\t\t\t\t\t\t" . $idColName . " = '" . $id . "' \n\t\t\t\t\t\tand " . $parentColName . " = '" . $parentId . "' \n\t\t\t\t\t)\n\t\t\t\t\t" . ($parameters['BIDIRECTIONAL'] ? "\n\n\t\t\t\t\tor\n\t\t\t\t\t(\n\t\t\t\t\t\t" . $idColName . " = '" . $parentId . "' \n\t\t\t\t\t\tand " . $parentColName . " = '" . $id . "' \n\t\t\t\t\t)\n\n\t\t\t\t\t" : "") . "\n\t\t\t")->fetch();
return is_array($item);
}
示例7: deleteByTemplateId
/**
* Removes all checklist's items for given template.
* This function is low-level, i.e. it disrespects any events\callbacks
*
* @param integer $templateId
* @throws \Bitrix\Main\ArgumentException
*/
public static function deleteByTemplateId($templateId)
{
$templateId = Assert::expectIntegerPositive($templateId, '$templateId');
\Bitrix\Main\HttpApplication::getConnection()->query("DELETE FROM " . static::getTableName() . " WHERE TEMPLATE_ID = '" . $templateId . "'");
}
示例8: resetAutoIncrement
public static function resetAutoIncrement($tableName, $startIndex = 1)
{
$startIndex = intval($startIndex);
if ($startIndex <= 0 || !strlen($tableName)) {
return false;
}
$dbConnection = Main\HttpApplication::getConnection();
$dbHelper = $dbConnection->getSqlHelper();
$dbName = $dbConnection->getDbName();
$tableName = $dbHelper->forSql(trim($tableName));
$dbConnection->query("DBCC CHECKIDENT('" . $dbName . ".dbo." . $tableName . "', RESEED, " . ($startIndex - 1) . ")");
return true;
}
示例9: create
public function create()
{
$dbConnection = Main\HttpApplication::getConnection();
$table = static::getTableName();
global $DB;
if (!$DB->query('select * from ' . $table . ' where 1=0', true)) {
$dbConnection->query("create table " . $table . " (\n\n\t\t\t\tID int not null auto_increment primary key,\n\n\t\t\t\tCODE varchar(100),\n\t\t\t\tPARENT_CODE varchar(100),\n\n\t\t\t\tSYS_CODE varchar(100),\n\n\t\t\t\tTYPE_CODE varchar(20),\n\t\t\t\tFIAS_TYPE varchar(10),\n\n\t\t\t\tNAME varchar(100) not null,\n\t\t\t\tNAME_UA varchar(100) not null,\n\t\t\t\tZIP varchar(10),\n\t\t\t\tZIP_TO varchar(10),\n\n\t\t\t\tLANGNAMES varchar(300),\n\t\t\t\tEXTERNALS varchar(200),\n\n\t\t\t\tLATITUDE varchar(30),\n\t\t\t\tLONGITUDE varchar(30),\n\n\t\t\t\tALTERNATE_COORDS varchar(100),\n\t\t\t\tBOUNDED_WITH varchar(100),\n\n\t\t\t\tSOURCE varchar(2) default 'U'\n\t\t\t)");
// SYS_CODE will be U_ + settlement id
$this->restoreIndexes();
}
}
示例10: prepareSql
protected function prepareSql($row)
{
if(!is_array($row) || empty($row))
return '';
$sql = array();
foreach($this->fldVector as $fld => $none)
{
$val = $row[$fld];
// only numeric and literal fields supported at the moment
if($this->tableMap[$fld]['data_type'] == 'integer')
$sql[] = intval($val);
else
$sql[] = "'".Main\HttpApplication::getConnection()->getSqlHelper()->forSql($val)."'";
}
return '('.implode(',', $sql).')';
}
示例11: truncateTable
public static function truncateTable($tableName)
{
$dbConnection = Main\HttpApplication::getConnection();
$tableName = $dbConnection->getSqlHelper()->forSql($tableName);
if ($dbConnection->isTableExists($tableName)) {
Main\HttpApplication::getConnection()->query('truncate table ' . $tableName);
}
}
示例12: initializeData
public function initializeData()
{
$dbConnection = Main\HttpApplication::getConnection();
$res = Location\LocationTable::getList(array('select' => array('ID', 'TYPE_ID', 'DEPTH_LEVEL', 'SORT'), 'order' => array('LEFT_MARGIN' => 'asc'), 'limit' => self::STEP_SIZE, 'offset' => $this->procData['OFFSET']));
$this->procData['TYPE_SORT'] = $this->rarefact($this->procData['TYPE_SORT']);
$cnt = 0;
while ($item = $res->fetch()) {
// tmp!!!!
//$name = Location\Name\LocationTable::getList(array('select' => array('NAME'), 'filter' => array('=LOCATION_ID' => $item['ID'], '=LANGUAGE_ID' => 'ru')))->fetch();
if ($item['DEPTH_LEVEL'] < $this->procData['DEPTH']) {
$newPC = array();
foreach ($this->procData['PATH'] as $dl => $id) {
if ($dl >= $item['DEPTH_LEVEL']) {
break;
}
$newPC[$dl] = $id;
}
$this->procData['PATH'] = $newPC;
}
$this->procData['PATH'][$item['DEPTH_LEVEL']] = array('TYPE' => $item['TYPE_ID'], 'ID' => $item['ID']);
if (is_array($this->procData['ALLOWED_TYPES']) && in_array($item['TYPE_ID'], $this->procData['ALLOWED_TYPES'])) {
$data = array('LOCATION_ID' => $item['ID'], 'RELEVANCY' => $this->procData['TYPE_SORT'][$item['TYPE_ID']] + $item['SORT']);
$wordsAdded = array();
/*
_dump_r('############################');
_dump_r('LOCATION: '.$name['NAME']);
_dump_r('TYPE RELEVANCY: '.$data['RELEVANCY']);
_dump_r('PATH:');
_dump_r($this->procData['PATH']);
*/
$this->procData['DEPTH'] = $item['DEPTH_LEVEL'];
// pre-load missing words
$wordCount = 0;
foreach ($this->procData['PATH'] as &$pathItem) {
if (!isset($pathItem['WORDS'])) {
$sql = "\n\t\t\t\t\t\t\tselect WS.POSITION from " . WordTable::getTableNameWord2Location() . " WL\n\t\t\t\t\t\t\t\tinner join " . WordTable::getTableName() . " WS on WL.WORD_ID = WS.ID\n\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\tWL.LOCATION_ID = '" . intval($pathItem['ID']) . "'\n\t\t\t\t\t\t";
$wordRes = $dbConnection->query($sql);
$pathItem['WORDS'] = array();
while ($wordItem = $wordRes->fetch()) {
$pathItem['WORDS'][] = $wordItem['POSITION'];
}
$pathItem['WORDS'] = array_unique($pathItem['WORDS']);
}
$wordCount += count($pathItem['WORDS']);
}
// count words
//_dump_r('Words total: '.$wordCount);
$wOffset = 0;
foreach ($this->procData['PATH'] as &$pathItem) {
foreach ($pathItem['WORDS'] as $i => $position) {
$wordWeight = $wordCount - $wOffset;
$tmpData = $data;
$tmpData['RELEVANCY'] += $wordWeight;
//_dump_r(' Word relevancy: '.$data['RELEVANCY'].' ==>> '.$tmpData['RELEVANCY']);
if (!isset($wordsAdded[$position])) {
$this->indexInserter->insert(array_merge(array('POSITION' => $position), $tmpData));
$wordsAdded[$position] = true;
}
$wOffset++;
}
}
unset($pathItem);
}
$cnt++;
}
$this->indexInserter->flush();
$this->procData['OFFSET'] += self::STEP_SIZE;
return !$cnt;
}
示例13: cleanUp
public static function cleanUp()
{
Main\HttpApplication::getConnection()->query('truncate table ' . static::getTableName());
}
示例14: findNoIndex
/**
*
*
* @param
*
* @return
*/
protected static function findNoIndex($parameters)
{
$dbConnection = Main\HttpApplication::getConnection();
$dbHelper = $dbConnection->getSqlHelper();
// tables
$locationTable = Location\LocationTable::getTableName();
$locationNameTable = Location\Name\LocationTable::getTableName();
$locationGroupTable = Location\GroupLocationTable::getTableName();
$locationSiteTable = Location\SiteLocationTable::getTableName();
$locationTypeTable = Location\TypeTable::getTableName();
//////////////////////////////////
// sql parameters prepare
//////////////////////////////////
$filter = static::parseFilter($parameters['filter']);
if (strlen($filter['SITE_ID']['VALUE'])) {
$filterSite = $dbHelper->forSql(substr($filter['SITE_ID']['VALUE'], 0, 2));
$hasLocLinks = Location\SiteLocationTable::checkLinkUsage($filterSite, Location\SiteLocationTable::DB_LOCATION_FLAG);
$hasGrpLinks = Location\SiteLocationTable::checkLinkUsage($filterSite, Location\SiteLocationTable::DB_GROUP_FLAG);
$doFilterBySite = true;
}
if (strlen($filter['PHRASE']['VALUE'])) {
$doFilterByName = true;
$filterName = ToUpper($dbHelper->forSql($filter['PHRASE']['VALUE']));
}
if (intval($filter['ID']['VALUE'])) {
$doFilterById = true;
$filterId = intval($filter['ID']['VALUE']);
}
if (intval($filter['CODE']['VALUE'])) {
$doFilterByCode = true;
$filterCode = $dbHelper->forSql($filter['CODE']['VALUE']);
}
$doFilterByLang = true;
if (strlen($filter['NAME.LANGUAGE_ID']['VALUE'])) {
$filterLang = $dbHelper->forSql(substr($filter['NAME.LANGUAGE_ID']['VALUE'], 0, 2));
} else {
$filterLang = LANGUAGE_ID;
}
if (isset($filter['PARENT_ID']) && intval($filter['PARENT_ID']['VALUE']) >= 0) {
$doFilterByParent = true;
$filterParentId = intval($filter['PARENT_ID']['VALUE']);
}
if (intval($filter['TYPE_ID']['VALUE'])) {
$doFilterByType = true;
$filterTypeId = intval($filter['TYPE_ID']['VALUE']);
}
// filter select fields
if (!is_array($parameters['select'])) {
$parameters['select'] = array();
}
$map = Location\LocationTable::getMap();
$nameAlias = false;
foreach ($parameters['select'] as $alias => $field) {
if ($field == 'CHILD_CNT') {
$doCountChildren = true;
}
if ($field == 'NAME.NAME') {
$nameAlias = $alias;
}
if (!isset($map[$field]) || !in_array($map[$field]['data_type'], array('integer', 'string', 'float', 'boolean')) || isset($map[$field]['expression'])) {
unset($parameters['select'][$alias]);
}
}
//////////////////////////////////
// sql query build
//////////////////////////////////
// mandatory fields to be selected anyway
// alias => field
$fields = array('L.ID' => 'L.ID', 'L.CODE' => 'L.CODE', 'L.SORT' => 'L.SORT', 'LT_SORT' => 'LT.DISPLAY_SORT');
if ($nameAlias === false || !preg_match('#^[a-zA-Z0-9]+$#', $nameAlias)) {
$fields['NAME'] = 'LN.NAME';
} else {
$fields[$nameAlias] = 'LN.NAME';
}
$fields = array_merge($fields, array('L.LEFT_MARGIN' => 'L.LEFT_MARGIN', 'L.RIGHT_MARGIN' => 'L.RIGHT_MARGIN'));
$groupFields = $fields;
// additional fields to select
foreach ($parameters['select'] as $alias => $fld) {
$lFld = 'L.' . $fld;
// check if field is already selected
if ((string) $alias === (string) intval($alias)) {
// already selected
if (in_array($lFld, $fields)) {
continue;
}
$fields[$lFld] = $lFld;
//$groupFields[$lFld] = $lFld;
} else {
if (isset($fields[$alias])) {
continue;
}
$fields[$alias] = $lFld;
//$groupFields[$alias] = $lFld;
//.........这里部分代码省略.........
示例15: search
public static function search($words, $offset)
{
$dbConnection = Main\HttpApplication::getConnection();
$dbHelper = Main\HttpApplication::getConnection()->getSqlHelper();
$where = array();
foreach ($words as $word) {
$whereWord = array();
for ($k = 1; $k <= 10; $k++) {
$whereWord[] = "W_" . $k . " like '" . $dbHelper->forSql($word) . "%'";
}
$where[] = '(' . implode(' or ', $whereWord) . ')';
}
$sql = "\n\t\t\tselect SQL_NO_CACHE IX.LOCATION_ID as ID, L.CODE, IX.TYPE_ID, L.LEFT_MARGIN, L.RIGHT_MARGIN, N.NAME as NAME from " . static::getTableName() . " IX\n\n\t\t\t\tinner join b_sale_location L on IX.LOCATION_ID = L.ID\n\t\t\t\tinner join b_sale_loc_name N on IX.LOCATION_ID = N.LOCATION_ID and N.LANGUAGE_ID = 'ru'\n\n\t\t\t\twhere " . implode(' and ', $where) . "\n\n\t\t\torder by \n\t\t\t\tIX.SORT asc,\n\t\t\t\tIX.TYPE_SORT asc\n\t\t\tlimit 10\n\t\t\t" . (intval($offset) ? 'offset ' . intval($offset) : '') . "\n\t\t";
_dump_r($sql);
/*
print('<pre>');
print_r($sql);
print('</pre>');
*/
return $dbConnection->query($sql);
}