簡體   English   中英

PHP odbc_fetch_row非常慢

[英]PHP odbc_fetch_row VERY SLOW

總之,在PHP中使用帶有SQL Server 2012的odbc_fetch_row()時,需要17秒才能循環525個結果。

環境:

  • Mac OS X 10.9
  • Apache(隨os x一起提供)
  • 來自http://php-osx.liip.ch/的 PHP 5.5.8
  • ODBC驅動程序:實際的SQL Server
  • SQL Server 2012

odbc.ini文件內容:

[ODBC Data Sources]
theDb           = Actual SQL Server

[theDb]
Driver         = /Library/ODBC/Actual SQL Server.bundle/Contents/MacOS/atsqlsrv.so
Description    = Production SQL Server
Server         = [some address]
Database       = [some db]
ServerName     = theDb
host           = [some address]

PHP測試頁面:

<?php

$userID="[user]";
$password="[password]";
$driverSourceString="theDb";

$dbc = odbc_connect($driverSourceString, $userID, $password);

$time_start=0;

function startTimer(){
    global $time_start;
    $time_start = microtime(true);
}

function printTimer(){
    global $time_start;
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    echo sprintf('%f', $time);
    echo " Seconds";
}

?>

<html>
<head>
    <title>SQL TEST</title>
</head>
<body>

    <pre>

    Connection:
    <?php
        startTimer();
        $dbc = odbc_connect($driverSourceString, $userID, $password);
        printTimer();
    ?>


    Query:
    <?php
        startTimer();
        $query = "SELECT m.firstName + ' ' + m.lastName AS username FROM models m ORDER BY lastName ASC";
        $result = odbc_exec($dbc, $query);
        printTimer();
    ?>


    Fetchrow:
    <?php
        startTimer();
        while(odbc_fetch_row($result))
        {
            //do nothing
        }
        printTimer();
    ?>

    </pre>

</body>
</html>

輸出:

Connection:
0.000129 Seconds

Query:
0.061282 Seconds

Fetchrow:
15.795249 Seconds (WHY SO LONG??)

我還使用php odbc從MSSQL數據庫中獲取結果時遇到了一些嚴重的性能問題。 對我來說,解決方案是在連接中指定游標類型:

$con = odbc_connect([dsn], [user], [pwd], SQL_CUR_USE_ODBC)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM