You are here

function ldap_server::search in Lightweight Directory Access Protocol (LDAP) 6

Preform an LDAP search.

@peram string $filter The search filter. @peram strign $basedn The search base. If NULL, we use $this->basedn @peram array $attributes List of desired attributes. If omitted, we only return "dn".

Return value

An array of matching entries->attributes, or FALSE if the search is empty.

File

includes/ldap.server.inc, line 220
Defines server classes and related functions.

Class

ldap_server
LDAP Server Class

Code

function search($filter, $basedn = NULL, $attributes = array()) {
  $basedn = $basedn != NULL ? $basedn : $this->basedn;
  $attributes = attributes != NULL ? $attributes : 'dn';

  // Change the error handler, ldap_search throws exceptions when results
  // are NULL
  set_error_handler(array(
    'ldap_server',
    'error_handler',
  ));
  $result = @ldap_search($this->connection, $basedn, $filter, $attributes);
  restore_error_handler();
  if ($result && ldap_count_entries($this->connection, $result)) {
    return ldap_get_entries($this->connection, $result);
  }
  return FALSE;
}