0

これは私の元の構文です:

$dn = "OU=Users,OU=NA1,DC=corp,DC=pvt";

に OU をもう 1 つ追加します$dn

ディレクトリ構成は以下の通りです。
OU=NA1、NA1の下に2つのアクティブなディレクトリがあります:ユーザーと連絡先

したがって、以下のように、両方のアクティブ ディレクトリを 1 行で呼び出したいと思います。(注: この構文は機能しません)

$dn = "OU=Users+Contacts,OU=NA1,DC=corp,DC=pvt"; 

両方のアクティブ ディレクトリを 1 行に追加する方法はありますか?

4

1 に答える 1

1

読み取り操作については、PHP は並列検索と呼ばれる機能をサポートしています。これは思ったほど単純ではありませんが、1 回の操作で目的の結果を得ることができます。

$links = array($link, $link); // yes, two references to the same link

$DNs = array(
    'OU=Users,OU=NA1,DC=corp,DC=pvt',
    'OU=Contacts,OU=NA1,DC=corp,DC=pvt'
);

$filter = 'attr=val';

// a regular call to ldap_search()
// only now, $results is and array of result identifiers
$results = ldap_search($links, $DNs, $filter);

これを次のような関数にラップして、呼び出しをより簡単にすることができます。

function ldap_multi_search($link, array $dns, $filter, array $attributes = null, $attrsonly = null, $sizelimit = null, $timelimit = null, $deref = null)
{
    $dns = array_values($dns);
    $links = array_fill(0, count($dns), $link);

    $results = ldap_search($links, $dns, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref);

    $retVal = array();
    foreach ($results as $i => $result) {
        if ($result === false) {
            trigger_error('LDAP search operation returned error for DN ' . $dns[$i], E_USER_WARNING);
            continue;
        }

        $entries = ldap_get_entries($result);
        unset($result['count']); // we'll calculate this properly at the end

        $retVal = array_merge($retVal, array_values($entries));
    }
    $entries['count'] = count($entries);

    return $entries;
}
于 2013-07-19T14:51:57.027 に答える