title: Windows Search w/PHP
body: <p>I have a basic PHP script to query the index using Windows Search that recently stopped functioning.</p>
  <p>The script returns results from the index--so that much still works--but a fatal error occurs when the script apparently fails to recognize it should stop looping through the recordset.  Here's a PHP log excerpt in which you can see that results are found and returned and then the script dies:</p>
  <blockquote>
  <p>[11-Jul-2017 09:55:13 America/New_York]
  Copyofguidance.58de8e890c10e.xlsx</p>
  <p>[11-Jul-2017 09:55:13 America/New_York]
  SRFWebsiteSchedule.5876a0ab683a8.xlsx</p>
  <p>[11-Jul-2017 09:55:13 America/New_York]
  CSI_D01_S04_T03_STEP.5877ad8385974.pdf</p>
  <p>[11-Jul-2017 09:55:13 America/New_York]
  Copyofguidance.58cbf217868d9.xlsx</p>
  <p>[11-Jul-2017 09:55:13 America/New_York]
  Copyofguidance.58cbf39ca3955.xlsx</p>
  <p>[11-Jul-2017 09:55:13 America/New_York]
  Copyofguidance.58cbf565194fc.xlsx</p>
  <p>[11-Jul-2017 09:55:13 America/New_York] PHP Fatal error:  Uncaught
  exception 'com_exception' with message '<b>Source:</b>
  Unknown<br/><b>Description:</b> Unspecified error' in
  C:\WEB\srf\scripts\windowsSearch.php:149 Stack trace:</p>
  <h1>0 C:\WEB\srf\scripts\windowsSearch.php(149): com-&gt;moveNext()</h1>
  <h1>1 {main}   thrown in C:\WEB\srf\scripts\windowsSearch.php on line 149</h1>
  </blockquote>
  <p>And here are the relevant lines of code:</p>
  <pre><code>$conn = new COM('ADODB.Connection');
  $rs = new COM('ADODB.Recordset');
  
  $provider = &quot;Provider=Search.CollatorDSO;Extended &quot;
          . &quot;Properties='Application=Windows';&quot;;
  $conn-&gt;open($provider);
  $str = &quot;SELECT System.ItemName, System.DateModified FROM SYSTEMINDEX &quot;
          . &quot;WHERE DIRECTORY='&quot; 
          . $nPath . &quot;' AND CONTAINS('\&quot;&quot; 
          . $kw . &quot;\&quot;')&quot;;     
      $rs-&gt;cursorLocation = 3;
      $rs-&gt;lockType = 1;
      $rs-&gt;cursorType = 3;
      $rs-&gt;activeConnection = $conn;
      $rs-&gt;open($str);
  if (!($rs-&gt;bof &amp;&amp; $rs-&gt;eof)) {  
      $rs-&gt;moveFirst();
      while (!$rs-&gt;eof) { 
          error_log($rs-&gt;Fields['System.ItemName']-&gt;value);
          $rs-&gt;moveNext();
      }
  }
  </code></pre>
  <p>I've noticed that the recordCount method throws a fatal error as well.  I'm not sure what could have changed to cause this issue, or whether or not there is another method that could be used as a workaround.</p>
  <p>Other code using ADO continues to run without problem, although that code connects to SQL Server, not Windows Search.</p>
  <p>The Windows 2008 R2 server receives regular patches and PHP was recently updated to 5.6.30.  Downgrading isn't really an option, even if that turned out to be the issue...</p>
  <p>If I've left out any useful information, please let me know.  Thank you.</p>