title: ldap_search() error: Success
body: <p>This is my code:</p>
  
  <pre><code>$objLDAP = ldap_connect($_POST['host']);
  $dn      = "OU=Users,DC=office,DC=example,DC=com";
  if ($objLDAP)
  {
      ldap_set_option($objLDAP, LDAP_OPT_REFERRALS, 0);
      ldap_get_option($objLDAP,LDAP_OPT_REFERRALS,$error);
      print_r($error."&lt;br/&gt;");
      ldap_set_option($objLDAP, LDAP_OPT_PROTOCOL_VERSION, 3);
      ldap_get_option($objLDAP,LDAP_OPT_PROTOCOL_VERSION,$error);
      print_r($error."&lt;br/&gt;");
  
      $objBind = ldap_bind($objLDAP);
      print_r($objBind."&lt;br/&gt;");
  
      $sr = ldap_search($objLDAP, $dn, "sn=*","sn") or die("Error in search query: ".ldap_error($objLDAP));
      print_r($sr."&lt;br /&gt;");
      print_r(ldap_error($objLDAP)."&lt;br /&gt;");
  
      $info = ldap_get_entries($objLDAP, $sr);
      print_r($info["count"]);
      print_r(ldap_error($objLDAP));
      exit();
  }
  </code></pre>
  
  <p>Where $_POST['host'] is a valid hostname, and $dn is also a valid tree. However, when I run the program, I am getting </p>
  
  <blockquote>
    <p>0<br/>
    3<br/>
    1<br/>
    Success<br/>
    Error in search query: Success</p>
  </blockquote>
  
  <p>If I use ldap_errno, then I get "Error in search query: 0".</p>
  
  <p>Can anyone please help me get more meaningful information back as to why I can't reach $info?</p>
  
  <p>Thank you.</p>
  
  <p>EDIT: 
  Still debugging. If I change the line to:</p>
  
  <pre><code>$sr = ldap_search($objLDAP,$dn,"(dn=*)") or die("Error in search query: ".ldap_error($objLDAP);
  </code></pre>
  
  <p>Then I get </p>
  
  <blockquote>
    <p>Error in search query: Operations error</p>
  </blockquote>
  
  <p>But the minute that I add in the fourth argument:</p>
  
  <pre><code>$sr = ldap_search($objLDAP,$dn,"(dn=*)","") or die("Error in search query: ".ldap_error($objLDAP);
  </code></pre>
  
  <p>Then I get:</p>
  
  <blockquote>
    <p>Error in search query: Success</p>
  </blockquote>
  
  <p>ANOTHER EDIT:
  Based on the comment below, I have taken the <code>or die()</code> out and simply continued with program flow. But I am still not getting any data in $info.</p>
  
  <p>Code:</p>
  
  <pre><code>    ldap_set_option($objLDAP, LDAP_OPT_REFERRALS, 0);
      ldap_get_option($objLDAP,LDAP_OPT_REFERRALS,$error);
      print_r($error.": LDAP_OPT_REFERRALS&lt;br/&gt;");
      ldap_set_option($objLDAP, LDAP_OPT_PROTOCOL_VERSION, 3);
      ldap_get_option($objLDAP,LDAP_OPT_PROTOCOL_VERSION,$error);
      print_r($error.": LDAP_OPT_PROTOCOL_VERSION&lt;br/&gt;");
  
      $objBind = ldap_bind($objLDAP);
      print_r($objBind.": objBind&lt;br/&gt;");
      print_r(ldap_error($objLDAP).": ldap_bind error&lt;br/&gt;");
      $sr = ldap_search($objLDAP,"OU=Users,DC=office,DC=example,DC=com","(sn=*)","");
      print_r($sr.": search result&lt;br /&gt;");
      print_r(ldap_error($objLDAP).": ldap_search error&lt;br /&gt;");
      $info = ldap_get_entries($objLDAP, $sr);
      print_r($info["count"].": number of entries returned&lt;br /&gt;");
      print_r(ldap_error($objLDAP.": ldap_get_entries error&lt;br /&gt;"));
      exit();
  </code></pre>
  
  <p>Result:</p>
  
  <blockquote>
    <p>0: LDAP_OPT_REFERRALS<br />
    3: LDAP_OPT_PROTOCOL_VERSION<br />
    1: objBind<br />
    Success: ldap_bind error<br />
    : search result<br />
    Success: ldap_search error<br />
    : number of entries returned<br /></p>
  </blockquote>