gpt4 book ai didi

PHP odbc_fetch_row 非常慢

转载 作者:行者123 更新时间:2023-12-04 22:04:50 24 4
gpt4 key购买 nike

总而言之,在 PHP 中将 odbc_fetch_row() 与 SQL Server 2012 结合使用时,循环 525 个结果需要 17 秒。

环境:

  • Mac OS X 10.9
  • Apache(随 os x 一起提供)
  • PHP 5.5.8 来自 http://php-osx.liip.ch/
  • 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)

关于PHP odbc_fetch_row 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22491016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com