<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 功能強大 支持多語言、二開方便! 廣告
                # PDO 與 MySQLi 二者效率簡單比較 ## 連接效率比較 ``` <?php $p_start_time = microtime(true); for ($i = 1; $i <= 100; $i++) { $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'aaaaaa'); } $p_end_time = microtime(true); $res = $p_end_time - $p_start_time; // PDO 連接方式耗時 $m_start_time = microtime(true); for ($i = 1; $i <= 100; $i++) { mysqli_connect('localhost', 'root', 'aaaaaa', 'test'); } $m_end_time = microtime(true); $res2 = $m_end_time - $p_start_time; // MySQL 連接方式耗時 var_dump($res, '<br />', $res2); if ($res > $res2) { echo 'PDO 連接數據庫是 MySQL 的' . round($res2 / $res) . '倍'; } else { echo 'MySQL 連接數據庫是 PDO 的' . round($res2 / $res) . '倍'; } ``` ## 寫入速度比較 ``` <?php // PDO 與 MySQLi 兩種連接方式寫入效率簡單比較 $p_start_time = microtime(true); $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'aaaaaa'); // 寫入數據表 $sql = <<<EOF CREATE TABLE IF NOT EXISTS test( id int unsigned not null )ENGINE=InnoDB CHARSET utf8 comment '寫入測試表'; EOF; $pdo->exec($sql); // 使用 PDO 預處理語句寫入 500 條數據到數據庫 $sql = 'INSERT INTO test VALUES(:id)'; $statement = $pdo->prepare($sql); for ($i = 1; $i <= 500; $i++) { $id = 1; $statement->bindParam(':id', $id, PDO::PARAM_INT); $statement->execute(); } unset($pdo); // 銷毀 PDO 對象 $p_end_time = microtime(true); $res = $p_end_time - $p_start_time; // PDO 連接方式耗時 $m_start_time = microtime(true); // 使用 MySQLi 連接方式寫入 500 條數據到數據庫 $link = mysqli_connect('localhost', 'root', 'aaaaaa', 'test'); for ($i = 1; $i <= 500; $i++) { $sql = 'INSERT INTO test VALUES (2)'; mysqli_query($link, $sql); } mysqli_close($link); // 關閉連接 $m_end_time = microtime(true); $res2 = $m_end_time - $p_start_time; // MySQL 連接方式耗時 var_dump($res, '<br />', $res2); if ($res > $res2) { echo 'PDO 連接數據庫寫入速度是 MySQL 的' . round($res2 / $res) . '倍'; } else { echo 'MySQL 連接數據庫寫入速度是 PDO 的' . round($res2 / $res) . '倍'; } ```
                  <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>

                              哎呀哎呀视频在线观看