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


PHP CDatabase::SlaveConnection方法代码示例

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


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

示例1: Query

 function Query($strSql, $bIgnoreErrors = false, $error_position = "", $arOptions = array())
 {
     global $DB;
     $this->DoConnect();
     $this->db_Error = "";
     if ($this->DebugToFile || $DB->ShowSqlStat) {
         $start_time = microtime(true);
     }
     //We track queries for DML statements
     //and when there is no one we can choose
     //to run query against master connection
     //or replicated one
     static $bSelectOnly = true;
     if ($this->bModuleConnection) {
         //In case of dedicated module database
         //were is nothing to do
     } elseif ($DB->bMasterOnly > 0) {
         //We requested to process all queries
         //by master connection
     } elseif (isset($arOptions["fixed_connection"])) {
         //We requested to process this query
         //by current connection
     } elseif ($this->bNodeConnection) {
         //It is node so nothing to do
     } else {
         $bSelect = preg_match('/^\\s*(select|show)/i', $strSql) && !preg_match('/get_lock/i', $strSql);
         if (!$bSelect && !isset($arOptions["ignore_dml"])) {
             $bSelectOnly = false;
         }
         if ($bSelect && $bSelectOnly) {
             if (!isset($this->obSlave)) {
                 $this->StartUsingMasterOnly();
                 //This is bootstrap code
                 $this->obSlave = CDatabase::SlaveConnection();
                 $this->StopUsingMasterOnly();
             }
             if (is_object($this->obSlave)) {
                 return $this->obSlave->Query($strSql, $bIgnoreErrors, $error_position, $arOptions);
             }
         }
     }
     $result = @mysql_query($strSql, $this->db_Conn);
     if ($this->DebugToFile || $DB->ShowSqlStat) {
         $exec_time = round(microtime(true) - $start_time, 10);
         if ($DB->ShowSqlStat) {
             $DB->cntQuery++;
             $DB->timeQuery += $exec_time;
             $DB->arQueryDebug[] = array("QUERY" => $strSql, "TIME" => $exec_time, "TRACE" => function_exists("debug_backtrace") ? debug_backtrace() : false, "BX_STATE" => $GLOBALS["BX_STATE"]);
         }
         if ($this->DebugToFile) {
             $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/mysql_debug.sql", "ab+");
             $str = "TIME: " . $exec_time . " SESSION: " . session_id() . "  CONN: " . $this->db_Conn . "\n";
             $str .= $strSql . "\n\n";
             $str .= "----------------------------------------------------\n\n";
             fputs($fp, $str);
             @fclose($fp);
         }
     }
     if (!$result) {
         $this->db_Error = mysql_error($this->db_Conn);
         $this->db_ErrorSQL = $strSql;
         if (!$bIgnoreErrors) {
             AddMessage2Log($error_position . " MySql Query Error: " . $strSql . " [" . $this->db_Error . "]", "main");
             if ($this->DebugToFile) {
                 $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/mysql_debug.sql", "ab+");
                 fputs($fp, "SESSION: " . session_id() . " ERROR: " . $this->db_Error . "\n\n----------------------------------------------------\n\n");
                 @fclose($fp);
             }
             if ($this->debug || @session_start() && $_SESSION["SESS_AUTH"]["ADMIN"]) {
                 echo $error_position . "<br><font color=#ff0000>MySQL Query Error: " . htmlspecialcharsbx($strSql) . "</font>[" . htmlspecialcharsbx($this->db_Error) . "]<br>";
             }
             $error_position = preg_replace("#<br[^>]*>#i", "\n", $error_position);
             SendError($error_position . "\nMySQL Query Error:\n" . $strSql . " \n [" . $this->db_Error . "]\n---------------\n\n");
             if (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/dbquery_error.php")) {
                 include $_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/dbquery_error.php";
             } elseif (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/dbquery_error.php")) {
                 include $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/dbquery_error.php";
             } else {
                 die("MySQL Query Error!");
             }
             die;
         }
         return false;
     }
     $res = new CDBResult($result);
     $res->DB = $this;
     if ($DB->ShowSqlStat) {
         $res->SqlTraceIndex = count($DB->arQueryDebug);
     }
     return $res;
 }
开发者ID:,项目名称:,代码行数:91,代码来源:


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