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

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

    2. <tfoot id='sBk60'></tfoot>

        創(chuàng)建一個(gè)全局可訪問(wèn)的 MySQLi 對(duì)象

        Creating a globally accessible MySQLi object(創(chuàng)建一個(gè)全局可訪問(wèn)的 MySQLi 對(duì)象)
          <bdo id='furKo'></bdo><ul id='furKo'></ul>
            <tbody id='furKo'></tbody>

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

            1. <legend id='furKo'><style id='furKo'><dir id='furKo'><q id='furKo'></q></dir></style></legend>

                <tfoot id='furKo'></tfoot>
                • <small id='furKo'></small><noframes id='furKo'>

                  本文介紹了創(chuàng)建一個(gè)全局可訪問(wèn)的 MySQLi 對(duì)象的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我有多個(gè)使用靜態(tài)方法的類(lèi).這些函數(shù)使用

                  I have multiple classes that use static methods. These functions connect to the database using

                  $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
                  

                  其中常量 DB_SERVER、DB_USER、DB_PASS、DB_NAME 是在全局可訪問(wèn)文件中定義的數(shù)據(jù)庫(kù)變量.最近,我的網(wǎng)站開(kāi)始變慢,在分析腳本后,我意識(shí)到創(chuàng)建對(duì)象 ($mysqli) 的調(diào)用導(dǎo)致了這個(gè)問(wèn)題.

                  where the constants DB_SERVER, DB_USER, DB_PASS, DB_NAME are database variables defined in a globally accessible file. Recently, my site started becoming slow and after profiling the script I realized that the call to create the object($mysqli) was causing this problem.

                  我的大部分類(lèi)都從 mysqli 擴(kuò)展,使得

                  Most of my classes extend from mysqli such that

                  public function __construct($user_id) {
                      parent::__construct(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
                      $this->retrieve_user_details($user_id);
                      $this->check_user_account_type();
                  
                  }
                  

                  據(jù)我所知,靜態(tài)方法不要使用 __construct 方法.

                  It is to my understanding that static methods DO NOT use the __construct method.

                  有人可以指導(dǎo)我如何創(chuàng)建 $mysqli 對(duì)象,以便所有需要它的靜態(tài)方法都可以訪問(wèn)它.

                  Could someone guide me on how I can create the $mysqli object once such that it can be accessed by all static methods that require it.

                  推薦答案

                  這是一種方法:

                  創(chuàng)建一個(gè)可以從任何地方靜態(tài)訪問(wèn)的單例類(lèi).

                  Create a singleton class, that can be accessed statically from anywhere.

                  class DBConnector {
                      private static $instance ;
                      public function __construct($host, $user, $password, $db){
                        if (self::$instance){
                          exit("Instance on DBConnection already exists.") ;
                        }
                      }
                  
                      public static function getInstance(){
                        if (!self::$instance){
                          self::$instance = new DBConnector(a,b,c,d) ;
                        }
                        return $instance ;
                      }
                  }
                  

                  一個(gè)例子是:

                  $mysqli = DBConnector::getInstance() ;
                  

                  但是我建議也使用另一種解決方案:

                  $mysqli = new MySQLi(a,b,c,d) ;
                  

                  然后你可以將該對(duì)象傳遞給其他類(lèi)(構(gòu)造函數(shù))

                  Then you could pass that object to other classes (constructor)

                  class Shop {
                    private $mysqli ;
                    public function __construct(MySQLi $mysqli){
                      $this->mysqli = $mysqli ;
                    }
                  }
                  
                  $show = new Shop($mysqli) ;
                  

                  這篇關(guān)于創(chuàng)建一個(gè)全局可訪問(wèn)的 MySQLi 對(duì)象的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)
                  <legend id='5xeq6'><style id='5xeq6'><dir id='5xeq6'><q id='5xeq6'></q></dir></style></legend>
                  • <tfoot id='5xeq6'></tfoot>
                      <tbody id='5xeq6'></tbody>
                      <bdo id='5xeq6'></bdo><ul id='5xeq6'></ul>

                          • <small id='5xeq6'></small><noframes id='5xeq6'>

                            <i id='5xeq6'><tr id='5xeq6'><dt id='5xeq6'><q id='5xeq6'><span id='5xeq6'><b id='5xeq6'><form id='5xeq6'><ins id='5xeq6'></ins><ul id='5xeq6'></ul><sub id='5xeq6'></sub></form><legend id='5xeq6'></legend><bdo id='5xeq6'><pre id='5xeq6'><center id='5xeq6'></center></pre></bdo></b><th id='5xeq6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5xeq6'><tfoot id='5xeq6'></tfoot><dl id='5xeq6'><fieldset id='5xeq6'></fieldset></dl></div>
                            主站蜘蛛池模板: 欧美a区 | 91精品国产综合久久婷婷香蕉 | 欧美一级淫片免费视频黄 | 国产精品成人一区二区 | 91av在线视频观看 | 精品国产第一区二区三区 | 久久精品亚洲 | 91在线视频免费观看 | 黄色大片免费网站 | 欧美成人a∨高清免费观看 色999日韩 | 免费成人在线网站 | 国产日韩欧美综合 | 日本一区二区三区在线观看 | 美女131mm久久爽爽免费 | 嫩草视频网 | 欧洲av在线 | 成人午夜在线 | 国产精品久久久久久久久久免费看 | 日韩一| 在线观看中文字幕 | 91久久国产综合久久 | 国产欧美一级 | www.青娱乐 | 高清黄色 | 国产精品1区 | 欧美一区久久 | 久久不射网 | 欧美激情精品久久久久 | 午夜久久久 | 亚洲精品久久久 | 亚洲激情一区二区三区 | 国产一区在线看 | 亚洲巨乳自拍在线视频 | www.操.com| 欧美日韩亚洲一区 | 国产小视频在线观看 | 欧美亚洲视频在线观看 | 日韩欧美在线视频 | 国产精品乱码一区二区三区 | 男人天堂久久 | 国产高清视频 |