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


PHP CDatabase::Query方法代码示例

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


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

示例1: query

 /**
  * @param $query
  * @param null $var1
  * @param null $var2
  * @return bool|\CDBResult
  */
 protected function query($query, $var1 = null, $var2 = null)
 {
     if (func_num_args() > 1) {
         $params = func_get_args();
         $query = call_user_func_array('sprintf', $params);
     }
     $search = array('#TABLE1#' => $this->tableName, '#DBNAME#' => $this->dbName);
     if (Locale::isWin1251()) {
         $search['#CHARSET#'] = 'cp1251';
         $search['#COLLATE#'] = 'cp1251_general_ci';
     } else {
         $search['#CHARSET#'] = 'utf8';
         $search['#COLLATE#'] = 'utf8_general_ci';
     }
     $querySearch = array_keys($search);
     $queryReplace = array_values($search);
     $query = str_replace($querySearch, $queryReplace, $query);
     return $this->bitrixDb->Query($query);
 }
开发者ID:andreyryabin,项目名称:sprint.migration,代码行数:25,代码来源:VersionTable.php

示例2: InstallDB

 function InstallDB()
 {
     /** @global string $DBType */
     global $DB, $DBType, $DBHost, $DBLogin, $DBPassword, $DBName, $APPLICATION;
     if (!is_object($APPLICATION)) {
         $APPLICATION = new CMain();
     }
     $DB = new CDatabase();
     $DB->DebugToFile = false;
     $DB->debug = true;
     if (!defined("DBPersistent")) {
         define("DBPersistent", false);
     }
     if (!$DB->Connect($DBHost, $DBName, $DBLogin, $DBPassword)) {
         $APPLICATION->ThrowException(GetMessage("MAIN_INSTALL_DB_ERROR"));
         return false;
     }
     $result = $DB->Query("SELECT * FROM b_module WHERE ID='main'", true, "", array("fixed_connection" => true));
     $success = $result && $result->Fetch();
     if ($success) {
         return true;
     }
     if ($DBType == "mysql" && defined("MYSQL_TABLE_TYPE") && strlen(MYSQL_TABLE_TYPE) > 0) {
         $DB->Query("SET storage_engine = '" . MYSQL_TABLE_TYPE . "'", true);
     }
     $errors = $DB->RunSQLBatch($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/install/" . $DBType . "/install.sql");
     if ($errors !== false) {
         $APPLICATION->ThrowException(implode("", $errors));
         return false;
     }
     $this->InstallTasks();
     $group = new CGroup();
     $arGroups = array(array("~ID" => 1, "ACTIVE" => "Y", "C_SORT" => 1, "NAME" => GetMessage("MAIN_ADMIN_GROUP_NAME"), "ANONYMOUS" => "N", "DESCRIPTION" => GetMessage("MAIN_ADMIN_GROUP_DESC")), array("~ID" => 2, "ACTIVE" => "Y", "C_SORT" => 2, "NAME" => GetMessage("MAIN_EVERYONE_GROUP_NAME"), "ANONYMOUS" => "Y", "DESCRIPTION" => GetMessage("MAIN_EVERYONE_GROUP_DESC")), array("~ID" => 3, "ACTIVE" => "Y", "C_SORT" => 3, "NAME" => GetMessage("MAIN_VOTE_RATING_GROUP_NAME"), "ANONYMOUS" => "N", "DESCRIPTION" => GetMessage("MAIN_VOTE_RATING_GROUP_DESC"), "STRING_ID" => "RATING_VOTE"), array("~ID" => 4, "ACTIVE" => "Y", "C_SORT" => 4, "NAME" => GetMessage("MAIN_VOTE_AUTHORITY_GROUP_NAME"), "ANONYMOUS" => "N", "DESCRIPTION" => GetMessage("MAIN_VOTE_AUTHORITY_GROUP_DESC"), "STRING_ID" => "RATING_VOTE_AUTHORITY"));
     foreach ($arGroups as $arGroup) {
         $rsGroup = CGroup::GetByID($arGroup["~ID"]);
         if ($rsGroup->Fetch()) {
             continue;
         }
         //mssql does not allow insert identity by default
         if (strtolower($DB->type) == "mssql") {
             unset($arGroup["~ID"]);
         }
         $success = (bool) $group->Add($arGroup);
         if (!$success) {
             $APPLICATION->ThrowException($group->LAST_ERROR);
             return false;
         }
     }
     self::InstallRatings();
     $arLanguages = array(array("LID" => LANGUAGE_ID, "ACTIVE" => "Y", "SORT" => 1, "DEF" => "Y", "NAME" => GetMessage("MAIN_DEFAULT_LANGUAGE_NAME"), "FORMAT_DATE" => GetMessage("MAIN_DEFAULT_LANGUAGE_FORMAT_DATE"), "FORMAT_DATETIME" => GetMessage("MAIN_DEFAULT_LANGUAGE_FORMAT_DATETIME"), "FORMAT_NAME" => GetMessage("MAIN_DEFAULT_LANGUAGE_FORMAT_NAME"), "CHARSET" => defined("BX_UTF") ? "UTF-8" : GetMessage("MAIN_DEFAULT_LANGUAGE_FORMAT_CHARSET")));
     if (LANGUAGE_ID != "en") {
         $arLanguages[] = array("LID" => "en", "ACTIVE" => "Y", "SORT" => 2, "DEF" => "N", "NAME" => "English", "FORMAT_DATE" => "MM/DD/YYYY", "FORMAT_DATETIME" => "MM/DD/YYYY H:MI:SS T", "FORMAT_NAME" => "#NAME# #LAST_NAME#", "CHARSET" => defined("BX_UTF") ? "UTF-8" : "iso-8859-1");
     }
     if (LANGUAGE_ID != "de" && file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/lang/de/install/index.php')) {
         $arLanguages[] = array("LID" => "de", "ACTIVE" => "Y", "SORT" => 3, "DEF" => "N", "NAME" => "German", "FORMAT_DATE" => "DD.MM.YYYY", "FORMAT_DATETIME" => "DD.MM.YYYY HH:MI:SS", "FORMAT_NAME" => "#NAME# #LAST_NAME#", "CHARSET" => defined("BX_UTF") ? "UTF-8" : "iso-8859-1");
     }
     if (LANGUAGE_ID != "ru" && file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/lang/ru/install/index.php')) {
         $arLanguages[] = array("LID" => "ru", "ACTIVE" => "Y", "SORT" => 3, "DEF" => "N", "NAME" => "Russian", "FORMAT_DATE" => "DD.MM.YYYY", "FORMAT_DATETIME" => "DD.MM.YYYY HH:MI:SS", "FORMAT_NAME" => "#NAME# #LAST_NAME#", "CHARSET" => defined("BX_UTF") ? "UTF-8" : "windows-1251");
     }
     $lang = new CLanguage();
     foreach ($arLanguages as $arLanguage) {
         $rsLang = CLanguage::GetByID($arLanguage["LID"]);
         if ($rsLang->Fetch()) {
             continue;
         }
         $success = (bool) $lang->Add($arLanguage);
         if (!$success) {
             $APPLICATION->ThrowException($lang->LAST_ERROR);
             return false;
         }
     }
     $arSite = array("LID" => "s1", "ACTIVE" => "Y", "SORT" => 1, "DEF" => "Y", "NAME" => GetMessage("MAIN_DEFAULT_SITE_NAME"), "DIR" => "/", "FORMAT_DATE" => GetMessage("MAIN_DEFAULT_SITE_FORMAT_DATE"), "FORMAT_DATETIME" => GetMessage("MAIN_DEFAULT_SITE_FORMAT_DATETIME"), "FORMAT_NAME" => GetMessage("MAIN_DEFAULT_SITE_FORMAT_NAME"), "CHARSET" => defined("BX_UTF") ? "UTF-8" : GetMessage("MAIN_DEFAULT_SITE_FORMAT_CHARSET"), "LANGUAGE_ID" => LANGUAGE_ID);
     $rsSites = CSite::GetByID($arSite["LID"]);
     if (!$rsSites->Fetch()) {
         $site = new CSite();
         $success = (bool) $site->Add($arSite);
         if (!$success) {
             $APPLICATION->ThrowException($site->LAST_ERROR);
             return false;
         }
     }
     RegisterModule("main");
     RegisterModuleDependences('iblock', 'OnIBlockPropertyBuildList', 'main', 'CIBlockPropertyUserID', 'GetUserTypeDescription', 100, '/modules/main/tools/prop_userid.php');
     RegisterModuleDependences('main', 'OnUserDelete', 'main', 'CFavorites', 'OnUserDelete', 100, "/modules/main/classes/" . strtolower($GLOBALS["DB"]->type) . "/favorites.php");
     RegisterModuleDependences('main', 'OnLanguageDelete', 'main', 'CFavorites', 'OnLanguageDelete', 100, "/modules/main/classes/" . strtolower($GLOBALS["DB"]->type) . "/favorites.php");
     RegisterModuleDependences('main', 'OnUserDelete', 'main', 'CUserOptions', 'OnUserDelete');
     RegisterModuleDependences('main', 'OnChangeFile', 'main', 'CMain', 'OnChangeFileComponent');
     RegisterModuleDependences('main', 'OnUserTypeRightsCheck', 'main', 'CUser', 'UserTypeRightsCheck');
     RegisterModuleDependences('main', 'OnUserLogin', 'main', 'UpdateTools', 'CheckUpdates');
     RegisterModuleDependences('main', 'OnModuleUpdate', 'main', 'UpdateTools', 'SetUpdateResult');
     RegisterModuleDependences('main', 'OnUpdateCheck', 'main', 'UpdateTools', 'SetUpdateError');
     RegisterModuleDependences('main', 'OnPanelCreate', 'main', 'CUndo', 'CheckNotifyMessage');
     RegisterModuleDependences('main', 'OnAfterAddRating', 'main', 'CRatingsComponentsMain', 'OnAfterAddRating');
     RegisterModuleDependences('main', 'OnAfterUpdateRating', 'main', 'CRatingsComponentsMain', 'OnAfterUpdateRating');
     RegisterModuleDependences('main', 'OnSetRatingsConfigs', 'main', 'CRatingsComponentsMain', 'OnSetRatingConfigs');
     RegisterModuleDependences('main', 'OnGetRatingsConfigs', 'main', 'CRatingsComponentsMain', 'OnGetRatingConfigs');
     RegisterModuleDependences('main', 'OnGetRatingsObjects', 'main', 'CRatingsComponentsMain', 'OnGetRatingObject');
     RegisterModuleDependences('main', 'OnGetRatingContentOwner', 'main', 'CRatingsComponentsMain', 'OnGetRatingContentOwner');
     RegisterModuleDependences('main', 'OnAfterAddRatingRule', 'main', 'CRatingRulesMain', 'OnAfterAddRatingRule');
     RegisterModuleDependences('main', 'OnAfterUpdateRatingRule', 'main', 'CRatingRulesMain', 'OnAfterUpdateRatingRule');
//.........这里部分代码省略.........
开发者ID:ASDAFF,项目名称:bitrix-5,代码行数:101,代码来源:index.php

示例3: AdjustServerID

 /**
  * @param array $arNode
  * @param CDatabase $nodeDB
  */
 function AdjustServerID($arNode, $nodeDB)
 {
     $rs = $nodeDB->Query("show variables like 'server_id'", false, '', array("fixed_connection" => true));
     if ($ar = $rs->Fetch()) {
         if ($ar["Value"] != $arNode["SERVER_ID"]) {
             $ob = new CClusterDBNode();
             $ob->Update($arNode["ID"], array("SERVER_ID" => $ar["Value"]));
         }
     }
 }
开发者ID:mrdeadmouse,项目名称:u136006,代码行数:14,代码来源:slave.php

示例4: CheckShortInstall

 function CheckShortInstall()
 {
     global $DB, $DBType, $DBHost, $DBLogin, $DBPassword, $DBName, $DBDebug, $DBSQLServerType;
     if (defined("SHORT_INSTALL_CHECK")) {
         return true;
     }
     //PHP
     $requireStep = new RequirementStep();
     if (!$requireStep->CheckRequirements($DBType)) {
         BXInstallServices::ShowStepErrors($requireStep);
     }
     //UTF-8
     if (defined("BX_UTF") && !BXInstallServices::IsUTF8Support()) {
         BXInstallServices::ShowStepErrors(InstallGetMessage("INST_UTF8_NOT_SUPPORT"));
     } elseif (defined("BX_UTF") && $DBType == "mssql") {
         BXInstallServices::ShowStepErrors(InstallGetMessage("INST_UTF8_NOT_SUPPORT"));
     }
     //Check connection
     require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/" . $DBType . "/database.php";
     require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/" . $DBType . "/main.php";
     require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/tools.php";
     IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/main.php");
     $DB = new CDatabase();
     if (!$DB->Connect($DBHost, $DBName, $DBLogin, $DBPassword)) {
         BXInstallServices::ShowStepErrors(InstallGetMessage("COULD_NOT_CONNECT") . " " . $DB->db_Error);
     }
     $databaseStep = new CreateDBStep();
     $databaseStep->DB =& $DB;
     $databaseStep->dbType = $DBType;
     $databaseStep->dbName = $DBName;
     $databaseStep->filePermission = defined("BX_FILE_PERMISSIONS") ? BX_FILE_PERMISSIONS : 0;
     $databaseStep->folderPermission = defined("BX_DIR_PERMISSIONS") ? BX_DIR_PERMISSIONS : 0;
     $databaseStep->createDBType = defined("MYSQL_TABLE_TYPE") ? MYSQL_TABLE_TYPE : "";
     $databaseStep->utf8 = defined("BX_UTF");
     $databaseStep->createCharset = null;
     $databaseStep->needCodePage = false;
     if ($databaseStep->IsBitrixInstalled()) {
         BXInstallServices::ShowStepErrors($databaseStep);
     }
     //Database check
     if ($DBType == "mysql") {
         $dbResult = $DB->Query("select VERSION() as ver", true);
         if ($dbResult && ($arVersion = $dbResult->Fetch())) {
             $mysqlVersion = trim($arVersion["ver"]);
             if (!BXInstallServices::VersionCompare($mysqlVersion, "5.0.0")) {
                 BXInstallServices::ShowStepErrors(InstallGetMessage("SC_DB_VERS_MYSQL_ER"));
             }
             $databaseStep->needCodePage = true;
             if (!$databaseStep->needCodePage && defined("BX_UTF")) {
                 BXInstallServices::ShowStepErrors(InstallGetMessage("INS_CREATE_DB_CHAR_NOTE"));
             }
         }
         //Code page
         if ($databaseStep->needCodePage) {
             $codePage = false;
             if (LANGUAGE_ID == "ru") {
                 $codePage = "cp1251";
             } elseif ($databaseStep->createCharset != '') {
                 $codePage = $databaseStep->createCharset;
             } else {
                 $codePage = 'latin1';
             }
             if ($databaseStep->utf8) {
                 $DB->Query("ALTER DATABASE `" . $databaseStep->dbName . "` CHARACTER SET UTF8 COLLATE utf8_unicode_ci", true);
             } elseif ($codePage) {
                 $DB->Query("ALTER DATABASE `" . $databaseStep->dbName . "` CHARACTER SET " . $codePage, true);
             }
         }
         if (strlen($databaseStep->createDBType) > 0) {
             $DB->Query("SET storage_engine = '" . $databaseStep->createDBType . "'", false);
         }
         //SQL mode
         $dbResult = $DB->Query("SELECT @@sql_mode", true);
         if ($dbResult && ($arResult = $dbResult->Fetch())) {
             $sqlMode = trim($arResult["@@sql_mode"]);
             if (strpos($sqlMode, "STRICT_TRANS_TABLES") !== false) {
                 $databaseStep->sqlMode = preg_replace("~,?STRICT_TRANS_TABLES~i", "", $sqlMode);
                 $databaseStep->sqlMode = ltrim($databaseStep->sqlMode, ",");
             }
         }
     } elseif ($DBType == "oracle" && $databaseStep->utf8) {
         $query = "SELECT * FROM nls_database_parameters WHERE PARAMETER='NLS_CHARACTERSET' OR PARAMETER='NLS_NCHAR_CHARACTERSET'";
         $dbResult = $DB->Query($query, true);
         if ($dbResult && ($arResult = $dbResult->Fetch())) {
             $arOracleParams = array("NLS_CHARACTERSET" => "", "NLS_NCHAR_CHARACTERSET" => "");
             foreach ($arResult as $arParam) {
                 $arOracleParams[$arParam["PARAMETER"]] = $arParam["VALUE"];
             }
             if ($arOracleParams["NLS_CHARACTERSET"] != "AL32UTF8" || $arOracleParams["NLS_NCHAR_CHARACTERSET"] != "UTF8") {
                 BXInstallServices::ShowStepErrors(InstallGetMessage("INST_ORACLE_UTF_ERROR"));
             }
         } else {
             BXInstallServices::ShowStepErrors(InstallGetMessage("INST_ORACLE_CHARSET_ERROR"));
         }
     }
     //Create after_connect.php if not exists
     if (!file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/after_connect.php") && $databaseStep->CreateAfterConnect() === false) {
         BXInstallServices::ShowStepErrors($databaseStep);
     }
     if (!$databaseStep->CheckDBOperation()) {
//.........这里部分代码省略.........
开发者ID:ASDAFF,项目名称:bitrix-5,代码行数:101,代码来源:utils.php


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