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

    <tfoot id='n1aHW'></tfoot>

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

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

      • <bdo id='n1aHW'></bdo><ul id='n1aHW'></ul>
      <legend id='n1aHW'><style id='n1aHW'><dir id='n1aHW'><q id='n1aHW'></q></dir></style></legend>
    2. 我應該將 $mysqli 變量傳遞給每個函數嗎?

      Should I pass my $mysqli variable to each function?(我應該將 $mysqli 變量傳遞給每個函數嗎?)

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

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

              <bdo id='aLXyD'></bdo><ul id='aLXyD'></ul>
                本文介紹了我應該將 $mysqli 變量傳遞給每個函數嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我在從 mysql_* 傳遞到面向對象的 mysqli 時遇到了一個小問題.

                I am having a little problem passing from mysql_* to mysqli object oriented.

                我的 index.php 文件的結構就像包含兩個文件:

                My index.php file is structured like including two files:

                include('connect.php');
                include('function.php');
                

                connect.php 文件包含:

                The connect.php file contains:

                <?php
                $mysqli = new mysqli("localhost", "root", "test", "test");
                
                if (mysqli_connect_errno($mysqli)) {
                    printf("Connection failed: %s
                ", mysqli_connect_error());
                    exit();
                }
                ?>
                

                function.php 文件中有一個名為 showPage 的函數,它不接受任何參數,但使用 $mysqli強> 連接,如...

                In the function.php file there is a function called showPage that takes no arguments but uses the $mysqli connection, in lines like...

                $result = $mysqli -> query("SELECT * FROM $table ORDER BY ID DESC"); // Seleziono tutto il contenuto della tabella
                

                如果不將 $mysqli 變量傳遞給函數,我就無法使其正常工作,但是當我使用 mysql_* 不推薦使用的函數時,這不是必需的!

                I cannot manage it to work without passing to the function the $mysqli variable, but this was not necessary when I used mysql_* deprecated functions!

                我能理解為什么嗎?解決這個問題的最佳方法是什么?

                Can I understand why, and what's the best way to resolve this?

                推薦答案

                用戶定義的函數在 PHP 中有自己的變量作用域.需要將$mysqli作為參數傳遞給函數,或者用global $mysqli啟動函數.

                User-defined functions have their own variable scope in PHP. You need to pass $mysqli to the function as a parameter, or start the function with global $mysqli.

                這個確切的問題作為變量作用域的一個例子給出頁面:

                This exact problem is given as an example on the Variable scope page:

                然而,在用戶定義的函數中,局部函數作用域是介紹.默認情況下,函數內部使用的任何變量都是僅限于局部函數范圍.比如這個腳本不會產生任何輸出,因為 echo 語句指的是本地$a 變量的版本,它沒有被賦值在這個范圍內.你可能會注意到這有點不同來自 C 語言,因為 C 中的全局變量是自動的可用于函數,除非被本地特別覆蓋定義.這可能會導致一些問題,因為人們可能無意中更改了全局變量.PHP中的全局變量必須如果要在函數中使用,則在函數中聲明為全局那個功能.

                However, within user-defined functions a local function scope is introduced. Any variable used inside a function is by default limited to the local function scope. For example, this script will not produce any output because the echo statement refers to a local version of the $a variable, and it has not been assigned a value within this scope. You may notice that this is a little bit different from the C language in that global variables in C are automatically available to functions unless specifically overridden by a local definition. This can cause some problems in that people may inadvertently change a global variable. In PHP global variables must be declared global inside a function if they are going to be used in that function.

                <?php
                $a = 1; /* global scope */ 
                
                function test()
                { 
                    echo $a; /* reference to local scope variable */ 
                } 
                
                test();
                ?>
                

                這篇關于我應該將 $mysqli 變量傳遞給每個函數嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                Call to undefined function mysqli_result::num_rows()(調用未定義的函數 mysqli_result::num_rows())
                PHP Prepared Statement Problems(PHP 準備好的語句問題)
                mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結果)
                PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
                How do I make sure that values from MySQL keep their type in PHP?(如何確保 MySQL 中的值在 PHP 中保持其類型?)
                • <bdo id='LPK1A'></bdo><ul id='LPK1A'></ul>
                • <small id='LPK1A'></small><noframes id='LPK1A'>

                    <tbody id='LPK1A'></tbody>

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

                          <tfoot id='LPK1A'></tfoot>

                          主站蜘蛛池模板: 亚洲九九| 成人免费视频网站在线看 | 日韩精品久久久久 | 日韩成人免费av | 国产精品一区二 | 99re在线视频免费观看 | 精品国产免费人成在线观看 | 国产91中文 | 国产精品一区二区av | 荷兰欧美一级毛片 | 丁香婷婷在线视频 | 国产福利91精品一区二区三区 | 在线观看成年视频 | 国产中文字幕在线 | 欧美三级电影在线播放 | 国产在线二区 | 久久久91精品国产一区二区三区 | 欧美日韩电影在线 | 日本人做爰大片免费观看一老师 | 美女福利视频一区 | 国产福利观看 | 久久久久亚洲国产| 国产成人精品久久二区二区91 | 影音av| 久久这里只有精品首页 | 乱一性一乱一交一视频a∨ 色爱av | 在线不卡 | 日本三级网站在线观看 | 黄视频免费观看 | 久久久久亚洲视频 | 国产成人免费一区二区60岁 | 欧美专区在线视频 | 免费久久久久久 | 欧美在线一区二区三区 | 精品国产乱码久久久久久影片 | 日韩成人在线观看 | 日本三级全黄三级三级三级口周 | 欧美h视频 | 女人毛片a毛片久久人人 | 国产精品欧美一区二区 | 伊人影院在线观看 |