I'm trying to get the Windows Indexing search work directly over PHP so I can search for text inside thousands of files very quickly.
I have it working on Visual Basic with this script:
'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
Now I'm trying to port it into PHP by using the COM class as suggested here but I'm getting this error message:
com_exception
Source: Unknown
Description: Unknown
My attempt looks like so:
<?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, "
" ;
}
What am I doing wrong?
I'm using PHP 5.5. and I'm using extension=php_com_dotnet.dll
at php.ini. The php_com_dotnet.dll file is placed at the ext
folder as detailed at the extension_dir
value.
Related question: