我使用odbc从php连接到dBase .dbf文件(由其他应用程序生成):
//database connection string
$dsn = "Driver={Microsoft dBASE Driver (*.dbf)};SourceType=DBF;DriverID=21;Dbq=".$GLOBALS['config']['pathToDbFiles'].";Exclusive=NO;collate=Machine;NULL=NO;DELETED=1;BACKGROUNDFETCH=NO;READONLY=false;";
//connect to database
$odbc=odbc_connect($dsn," "," ", SQL_CUR_USE_ODBC ) or die('Could Not Connect to ODBC Database!');
//query string
$query= $toSelect." FROM ".$dbFile." $conditions";
//query execution
$result = odbc_exec($odbc, $query) or die (odbc_errormsg());
考虑到:
查询执行速度非常慢......一些例子:
SELECT * FROM 03BOTESD.DBF WHERE F_NUMBOL=' 2203' AND F_DATBOL=#2011-07-30# // exec: 23ms
SELECT * FROM 03BORIGD.DBF WHERE F_NUMBOL=' 2203' AND F_DATBOL=#2011-07-30# // exec: 82ms
SELECT * FROM 03BORIGD.DBF WHERE F_NUMBOL=' 2203' AND F_DATBOL=#2011-07-30# AND F_PROGRE=3.0 // exec: 99ms
SELECT * FROM 03BORIGD.DBF WHERE F_NUMBOL=' 2203' AND F_DATBOL=#2011-07-30# AND F_PROGRE=5.0 // exec: 99ms
SELECT * FROM 03BORIGD.DBF WHERE F_NUMBOL=' 2203' AND F_DATBOL=#2011-07-30# AND F_PROGRE=7.0 // exec: 97ms
SELECT * FROM 03BORIGD.DBF WHERE F_NUMBOL=' 2203' AND F_DATBOL=#2011-07-30# AND F_PROGRE=9.0 // exec: 98ms
SELECT * FROM 03BOTESD.DBF WHERE F_NUMBOL=' 2204' AND F_DATBOL=#2011-07-30# // exec: 25ms
SELECT * FROM 03BORIGD.DBF WHERE F_NUMBOL=' 2204' AND F_DATBOL=#2011-07-30# // exec: 80ms
SELECT * FROM 03BORIGD.DBF WHERE F_NUMBOL=' 2204' AND F_DATBOL=#2011-07-30# AND F_PROGRE=3.0 // exec: 101ms
查看这些示例很清楚,文件越大,查询越慢。 奇怪的是,当查询指定更多参数(导致选择较少行的结果)时,执行速度较慢。
有没有办法以某种方式加快速度?
我已经搜索了很多关于它但没有找到真正的解决方案: