我正在尝试直接通过PHP进行Windows索引搜索,因此我可以非常快速地在数千个文件中搜索文本。
我使用这个脚本在Visual Basic上工作:
'To run this snippet, save it to a file and run it using cscript.exe from a command line.
'Running the .vbs file with Windows Script Host may cause dialog boxes to open for each item returned from the index.
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"
objRecordSet.Open "SELECT System.ItemName FROM SYSTEMINDEX WHERE DIRECTORY='file:C:/folderIndexed' AND CONTAINS('myDemo') ORDER BY System.ItemName DESC", objConnection
Do Until objRecordset.EOF
Wscript.Echo objRecordset.Fields.Item("System.ItemName")
objRecordset.MoveNext
Loop
现在我正在尝试使用建议COM class的here将其移植到PHP中,但我收到此错误消息:
发出com_exception
来源:未知
说明:未知
我的尝试看起来像这样:
<?php
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$conn->Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';");
$recordset = new COM("ADODB.Recordset");
$keyword = 'a';
$sql = "SELECT filename, size, path
FROM SCOPE()
WHERE DIRECTORY='file:C:/folderIndexed' and CONTAINS('a')";
//-----------------> line of the error <-----------------
$recordset = $recordset->Open($sql, $conn);
foreach ($recordset as $obj) {
echo $obj->Fields->Item("System.filename")->Value, "\ n" ;
}
我做错了什么?
我正在使用PHP 5.5。我在 php.ini 使用extension=php_com_dotnet.dll
。 php_com_dotnet.dll文件放在ext
文件夹中,详细信息为extension_dir
。
答案 0 :(得分:2)
$recordset->open
不会返回RecordSet,您不应该像正在那样分配返回值。
尝试更改:
$recordset = $recordset->Open($sql, $conn);
要
$recordset->Open($sql, $conn);
此外,您的移植代码明显偏离了VBScript版本的结构。这是我尝试移植您的代码,这对我有用。
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$recordset = new COM("ADODB.Recordset");
$conn->Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';");
// your query doesn't work for me in VBSCRIPT or PHP. this one does.
$recordset->Open("SELECT Top 5 System.ItemPathDisplay FROM SYSTEMINDEX", $conn);
if(!$recordset->EOF) $recordset->MoveFirst();
while(!$recordset->EOF) {
echo $recordset->Fields->Item("System.ItemPathDisplay")->Value . "\n";
$recordset->MoveNext();
}