<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] >[success]MySQL增強版擴展,MySQLi 函數允許您訪問 MySQL 數據庫服務器。MySQLi 擴展被設計用于 MySQL 4.1.13 版本或更新的版本,MySQLi提供面向過程和面向對象兩種接口 ## 查看是否支持 通過phpinfo()查看是否成功加載 >[danger]注意:如果沒加載,可以去php.ini看是否開啟該擴展,如果前面有分號去掉。 注意:如果沒有該擴展,百度"php mysqli擴展安裝",有很多場景下的解決方案。 ## 操作mysql流程 1. 建立mysql聯接 2. 發送查詢SQL 3. 從結果集中取出數據 4. 釋放資源 5. 關閉數據庫連接 ## 面向對象風格使用mysqli ### 實例mysqli對象,建立連接 ~~~ $mysqli = @new mysqli("localhost", "my_user", "my_password", "world"); ~~~ 返回創建后的數據鏈接對象 ### 錯誤信息反饋(對象屬性) ~~~ int $mysqli->connect_errno返回鏈接錯誤代碼 string $mysqli->connect_error;返回鏈接錯誤文本 int $mysqli->errno返回最近函數調用的錯誤代碼 string $mysqli->error;返回最近函數調用的錯誤文本 ~~~ ### 發送查詢 ~~~ mixed $mysqli->query (string $query ) ~~~ 對數據庫執行一次查詢 ### 通過結果集取數據 ~~~ mysqli_result::fetch_row() ~~~ 取得一行以索引數組形式返回的數據 ~~~ mysqli_result::fetch_assoc() ~~~ 取得一行以關聯數組形式返回的數據 ~~~ mysqli_result::fetch_object() ~~~ 取得一行以對象形式返回的數據 ~~~ mysqli_result::fetch_array($type) ~~~ 參數為返回結果的類型 參數:(MYSQLI_ASSOC 返回關聯數組 MYSQLI_NUM 返回索引數組 MYSQLI_BOTH 返回關聯不索引數組) ### 釋放結果內存 ~~~ mysqli_result::free() ~~~ 從內存中釋放結果集 ### 關閉鏈接 ~~~ mysqli::close() ~~~ 函數關閉非持久的 MySQL 連接。 ### 結果集數量 ~~~ mysqli_result::num_rows ~~~ ### 自增ID ~~~ mixed $mysqli->insert_id ~~~ ### 受影響數量 ~~~ int $mysqli->affected_rows; ~~~ ## MySQLi_STMT類(預準備) ### 預準備語句 每一條SQL的執行過程包括分析、編譯、優化查詢等操作,如果只是 SQL的參數不同而其他項一樣,那么可以想象,數據庫做了很多次重 復的分析、編譯、優化操作,顯然這種執行方式會降低效率。如果使 用預準備方式操作,這種分析、編譯、優化的操作只需要執行一次, 以后只是參數的不同,這樣效率會更快 先將SQL提交到MySQL服務器,預先解析,事后可以只傳遞參數到 MySQL服務器,減少解析次數、提高MySQL處理效率。 同時由于參數不是隨著SQL一起發送到服務器端,所以屏蔽了SQL 注入等等的危險操作 ### 綁定參數 可以事先在預先解析的SQL上指定占位符?號來為后面傳遞的值預 留空間位,可以把?想象成函數的形參這樣更好理解 ## 常用函數語法 ### 產生預準備對象 ~~~ mysqli_stmt mysqli::stmt_init ( void ) ~~~ 初始化一條語句并返回一個用于mysqli_stmt_prepare(調用)的對象 ~~~ mysqli_stmt mysqli::prepare ( $sql ) ~~~ ### 提交一個要執行的sql ~~~ mixed mysqli_stmt::prepare ( string $query ) ~~~ ### 綁定參數 ~~~ bool mysqli_stmt::bind_param ( string $types , mixed &$var1 [, mixed &$... ] ) ~~~ ### 執行預準備查詢 ~~~ bool mysqli_stmt::execute ( void ) ~~~ ### 受影響數量 ~~~ int $mysqli_stmt->affected_rows ~~~ ### 錯誤代碼 ~~~ int $mysqli_stmt->errno ~~~ ### 錯誤信息 ~~~ int $mysqli_stmt->errno ~~~ ### 最后插入的ID ~~~ int $mysqli_stmt->insert_id ~~~ **完整實例** ~~~ <?php $mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world'); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)"); //?占位符 $stmt->bind_param('sssd', $code, $language, $official, $percent); //sssd,前三個是字符串,最后一個是小數 $code = 'DEU'; $language = 'Bavarian'; $official = "F"; $percent = 11.2; /* execute prepared statement */ $stmt->execute(); printf("%d Row inserted.\n", $stmt->affected_rows); /* close statement and connection */ $stmt->close(); /* Clean up table CountryLanguage */ $mysqli->query("DELETE FROM CountryLanguage WHERE Language='Bavarian'"); printf("%d Row deleted.\n", $mysqli->affected_rows); /* close connection */ $mysqli->close(); ?> ~~~ ## 綁定參數類型參考 <table class=""> <caption><strong>Type specification chars</strong></caption> <thead> <tr> <th>Character</th> <th>Description</th> </tr> </thead><tbody class="tbody"> <tr> <td>i</td> <td>corresponding variable has type integer</td> </tr><tr> <td>d</td> <td>corresponding variable has type double</td> </tr><tr> <td>s</td> <td>corresponding variable has type string</td> </tr><tr> <td>b</td> <td>corresponding variable is a blob and will be sent in packets</td> </tr></tbody></table>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看