久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='c6ZAc'><tr id='c6ZAc'><dt id='c6ZAc'><q id='c6ZAc'><span id='c6ZAc'><b id='c6ZAc'><form id='c6ZAc'><ins id='c6ZAc'></ins><ul id='c6ZAc'></ul><sub id='c6ZAc'></sub></form><legend id='c6ZAc'></legend><bdo id='c6ZAc'><pre id='c6ZAc'><center id='c6ZAc'></center></pre></bdo></b><th id='c6ZAc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='c6ZAc'><tfoot id='c6ZAc'></tfoot><dl id='c6ZAc'><fieldset id='c6ZAc'></fieldset></dl></div>

      <legend id='c6ZAc'><style id='c6ZAc'><dir id='c6ZAc'><q id='c6ZAc'></q></dir></style></legend>

      • <bdo id='c6ZAc'></bdo><ul id='c6ZAc'></ul>

      1. <small id='c6ZAc'></small><noframes id='c6ZAc'>

        <tfoot id='c6ZAc'></tfoot>

        僅在需要時自動連接到 PDO

        Auto connecting to PDO only if needed(僅在需要時自動連接到 PDO)

          1. <i id='QPcaQ'><tr id='QPcaQ'><dt id='QPcaQ'><q id='QPcaQ'><span id='QPcaQ'><b id='QPcaQ'><form id='QPcaQ'><ins id='QPcaQ'></ins><ul id='QPcaQ'></ul><sub id='QPcaQ'></sub></form><legend id='QPcaQ'></legend><bdo id='QPcaQ'><pre id='QPcaQ'><center id='QPcaQ'></center></pre></bdo></b><th id='QPcaQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='QPcaQ'><tfoot id='QPcaQ'></tfoot><dl id='QPcaQ'><fieldset id='QPcaQ'></fieldset></dl></div>
              <tbody id='QPcaQ'></tbody>

            <small id='QPcaQ'></small><noframes id='QPcaQ'>

              <bdo id='QPcaQ'></bdo><ul id='QPcaQ'></ul>
              • <tfoot id='QPcaQ'></tfoot>
                • <legend id='QPcaQ'><style id='QPcaQ'><dir id='QPcaQ'><q id='QPcaQ'></q></dir></style></legend>
                  本文介紹了僅在需要時自動連接到 PDO的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一段代碼,根據請求的 URL,將包含其他十四個文件之一.這 14 個文件中的一些需要連接到三個不同數據庫之一,并且可以隨時添加其他文件.

                  I have a section of code that depending on the URL requested, will include one of fourteen other files. Some of these fourteen files require a connection to one of three different databases, and additional files can be added at anytime.

                  我不想默認打開所有三個數據庫的 PDO 連接,因為它浪費資源并且會減慢執行時間.所以我的想法是將所有 SQL 查詢包裝在一個函數中.第一次在未打開的 PDO 連接上執行查詢時,try {} 錯誤處理程序可以捕獲它,找出問題所在(在這種情況下連接不存在),然后打開連接并重新執行詢問.這樣,數據庫只在需要時才連接 - 只要連接字符串(主機、數據庫、用戶名、密碼)都預先定義,我看不出它有任何問題.

                  I don't want to open PDO connections by default to all three database as its a waste of resources and will slow the execution time down. So my thought is to wrap all SQL queries within a function. The first time that a query is executed on a non-open PDO connection, the try {} error handler can catch it, find out what the problem was (in this case connection doesnt exist), then open the connection and re-execute the query. That way, the database is only being connected to as and when needed - as long as the connection string (host, database, username, password) are all defined in advance, I can't see any problem in it working.

                  但是,我需要繼續推進,并且在大約 7 天內無法訪問開發箱,所以任何人都可以看出這種情況有什么問題嗎?另外,如果沒有打開連接,誰能告訴我 handler->errorInfo() 將返回的錯誤消息?

                  However, I need to push on with this, and don't have access to the dev box for about 7 days, so can anyone see any problem with that scenario? Also, can anyone give me the error message that handler->errorInfo() will return if the connection isn't opened?

                  推薦答案

                  這是正確的想法,但不是它的最佳實現.

                  This is the right idea, but not the best implementation of it.

                  包裝 SQL 操作很好.但是你為什么不這樣做呢:

                  Wrapping the SQL operations is good. But why don't you do it this way:

                  class Wrapper {
                      private static $db;
                  
                      public static function someQuery() {
                          $db = self::getDatabase();
                          // now go on to execute the query
                      }
                  
                      private static function getDatabase() {
                          if (self::$db === null) {
                              self::$db = // connect here
                          }
                          return self::$db;
                      }
                  }
                  

                  這有很多優點:

                  • 允許您在邏輯上將 SQL 操作分組為一個(或多個!)類
                  • 如果不需要,不連接到數據庫
                  • 不依賴(脆弱的)錯誤檢查來正常運行

                  在您的特定情況下,您可能應該使用 3 個單獨的 Wrapper 類.將所有內容都放在一個類中是可行的(三個不同的 $db 變量),但可能比它的價值更令人困惑.

                  In your specific case, you should probably go with 3 separate Wrapper classes. Putting everything into one class is doable (three different $db variables) but probably more confusing than it's worth.

                  這篇關于僅在需要時自動連接到 PDO的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                  <small id='6NGVX'></small><noframes id='6NGVX'>

                    <bdo id='6NGVX'></bdo><ul id='6NGVX'></ul>
                    <legend id='6NGVX'><style id='6NGVX'><dir id='6NGVX'><q id='6NGVX'></q></dir></style></legend>

                      <tfoot id='6NGVX'></tfoot>
                        <tbody id='6NGVX'></tbody>
                        <i id='6NGVX'><tr id='6NGVX'><dt id='6NGVX'><q id='6NGVX'><span id='6NGVX'><b id='6NGVX'><form id='6NGVX'><ins id='6NGVX'></ins><ul id='6NGVX'></ul><sub id='6NGVX'></sub></form><legend id='6NGVX'></legend><bdo id='6NGVX'><pre id='6NGVX'><center id='6NGVX'></center></pre></bdo></b><th id='6NGVX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6NGVX'><tfoot id='6NGVX'></tfoot><dl id='6NGVX'><fieldset id='6NGVX'></fieldset></dl></div>
                            主站蜘蛛池模板: 欧美精品网站 | 亚洲国产伊人 | 夜夜操天天艹 | 日韩欧美专区 | 日韩成人在线视频 | 国产精品国产精品国产专区不片 | h视频在线免费看 | 黄色在线免费观看视频网站 | 一级片网址 | 久久久久久一区 | 久久久久久中文字幕 | 亚洲高清在线观看 | 久久婷婷色 | 欧美在线a | 成人午夜在线观看 | 午夜av一区二区 | 欧美91| 特黄色一级毛片 | 欧美理论片在线观看 | 久久久久久久av | 国产一区二区影院 | 国产精品国产精品国产专区不卡 | 成人在线视频网 | 91精品国产乱码麻豆白嫩 | 亚洲精品在线观看网站 | 国产精品久久久久久久久 | 黑人巨大精品欧美一区二区一视频 | 国产日韩欧美精品一区二区 | 一区精品在线观看 | 欧美成人一区二免费视频软件 | 精品入口麻豆88视频 | 国产精品久久久久久久久久久免费看 | 色综合久久天天综合网 | 国内精品久久影院 | 欧美久久久久久久久 | 欧美一区二区三区在线 | 国产在线视频一区二区董小宛性色 | 伊人中文字幕 | 国产一区二区三区四区区 | 热久久久 | 精品国产乱码久久久久久88av |