title: LDAP Operations error
body: <p>I have a problem with ldap connection.</p>
  
  <pre><code>$hostname="ldap://sub.domain.com";
  $ds=ldap_connect($hostname, 389);
  ldap_set_option ($ds, LDAP_OPT_REFERRALS, 0) or die('Unable to set LDAP opt referrals');
  ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');
  
  if ($ds)
  {
  $dn = "OU=Users,OU=ro,DC=sub,DC=domain,DC=com";
  
  if (!($ldapc=ldap_bind($ds))) { 
      echo "&lt;p&gt;Error:" . ldap_error($ds) . "&lt;/p&gt;"; 
      echo "&lt;p&gt;Error number:" . ldap_errno($ds) . "&lt;/p&gt;"; 
      echo "&lt;p&gt;Error:" . ldap_err2str(ldap_errno($ds)) . "&lt;/p&gt;"; 
      die;
  } 
  
  $attributes = array("sn");
  $filter = "(sn=*)";
  $result = ldap_search($ds, $dn, $filter, $attributes);
  
  echo $result;
  $info = ldap_get_entries($ds, $result);
  for ($i=0; $i &lt; $info["count"]; $i++) {
      echo $info[$i]["ou"][0];
  }
  } else {
      echo "&lt;h4&gt;Unable to connect to LDAP server&lt;/h4&gt;";
  }
  
  ldap_unbind($ds);
  </code></pre>
  
  <p>The ldap any anonymous connection works because I test it in a AD browser and everything is fine.
  In this code it stops at</p>
  
  <pre><code>ldap_search($ds, $dn, $filter, $attributes);
  </code></pre>
  
  <p>I receive the warning:</p>
  
  <blockquote>
    <p>Warning: ldap_search(): Search: Operations error in ..\index.php on line 38</p>
  </blockquote>
  
  <p>I don't really know what can be the cause of this error, I appreciate your help.</p>