doq70020 2014-02-11 16:08
浏览 39
已采纳

使用Windows索引和PHP

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:
  • 写回答

1条回答 默认 最新

  • dongsang6899 2014-02-17 14:00
    关注

    $recordset->open does not return a RecordSet, you should not be assigning the return value as you are doing.

    Try changing:

    $recordset = $recordset->Open($sql, $conn);
    

    To

    $recordset->Open($sql, $conn);
    

    In addition, your ported code significantly deviates from structure of your VBScript version. Here is my attempt at porting your code, which works for me.

    $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 . "
    ";
        $recordset->MoveNext();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办