How to sort the search-result of ldap?

This is a discussion on How to sort the search-result of ldap? within the PHP Language forums, part of the PHP Programming Forums category; Hi, I want to sort the result of ldap_search. Unfortunatelly ldap_sort() is still not documented, so I don't have ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-07-2007
Florian Erfurth
 
Posts: n/a
Default How to sort the search-result of ldap?

Hi,
I want to sort the result of ldap_search. Unfortunatelly ldap_sort() is
still not documented, so I don't have Idea how to use it. :(

http://php.net/ldap_sort/

Could anyone of you help me? My code look as follow:
>>>

$ds = ldap_connect("LDAP://domain.tld");
$r =
ldap_bind($ds, "CN=searchfoo,OU=Guests,OU=Benutzergruppen,DC=doma in,DC=tld","longpassword");
$sr = @ldap_search($ds,"OU=Benutzergruppen, DC=domain, DC=tld", "Company=" .
$strCompany);
$sr = ldap_sort($ds, $sr, 'givenname');

ldap_sort($ds, $sr, 'givenname');
$info = ldap_get_entries($ds, $sr);

ldap_close($ds);
<<<

I get following error:
Warning: ldap_sort() expects parameter 2 to be resource, boolean given
in /usr/local/www/data-dist/test/telefonliste/index.php on line 9

Warning: ldap_get_entries(): supplied argument is not a valid ldap result
resource in /usr/local/www/data-dist/test/telefonliste/index.php on line 10

What should I do?
cu Floh
Reply With Quote
  #2 (permalink)  
Old 08-07-2007
Erwin Moller
 
Posts: n/a
Default Re: How to sort the search-result of ldap?

Florian Erfurth wrote:
> Hi,
> I want to sort the result of ldap_search. Unfortunatelly ldap_sort() is
> still not documented, so I don't have Idea how to use it. :(
>
> http://php.net/ldap_sort/
>
> Could anyone of you help me? My code look as follow:
> $ds = ldap_connect("LDAP://domain.tld");
> $r =
> ldap_bind($ds, "CN=searchfoo,OU=Guests,OU=Benutzergruppen,DC=doma in,DC=tld","longpassword");
> $sr = @ldap_search($ds,"OU=Benutzergruppen, DC=domain, DC=tld", "Company=" .
> $strCompany);
> $sr = ldap_sort($ds, $sr, 'givenname');
>
> ldap_sort($ds, $sr, 'givenname');
> $info = ldap_get_entries($ds, $sr);
>
> ldap_close($ds);
> <<<
>
> I get following error:
> Warning: ldap_sort() expects parameter 2 to be resource, boolean given
> in /usr/local/www/data-dist/test/telefonliste/index.php on line 9
>
> Warning: ldap_get_entries(): supplied argument is not a valid ldap result
> resource in /usr/local/www/data-dist/test/telefonliste/index.php on line 10
>
> What should I do?
> cu Floh


Hi

$sr = @ldap_search($ds,"OU=Benutzergruppen, DC=domain, DC=tld",
"Company=" . $strCompany);

Here you supress the error by using @.
I might very well return false or something, because the ldap_search was
wrong.

Stop surpressing it, and you'll get more possibly usefull information.

$sr = ldap_sort($ds, $sr, 'givenname');

Why don't you do a print_r($sr) before using it?

Regards,
Erwin Moller
Reply With Quote
  #3 (permalink)  
Old 08-07-2007
Florian Erfurth
 
Posts: n/a
Default Re: How to sort the search-result of ldap?

Erwin Moller wrote:

> Florian Erfurth wrote:
>> Hi,
>> I want to sort the result of ldap_search. Unfortunatelly ldap_sort() is
>> still not documented, so I don't have Idea how to use it. :(
>>
>> http://php.net/ldap_sort/
>>
>> Could anyone of you help me? My code look as follow:
>> $ds = ldap_connect("LDAP://domain.tld");
>> $r =
>> ldap_bind($ds,
>> "CN=searchfoo,OU=Guests,OU=Benutzergruppen,DC=doma in,DC=tld","longpassword");
>> $sr = @ldap_search($ds,"OU=Benutzergruppen, DC=domain, DC=tld",
>> "Company=" . $strCompany); $sr = ldap_sort($ds, $sr, 'givenname');
>>
>> ldap_sort($ds, $sr, 'givenname');
>> $info = ldap_get_entries($ds, $sr);
>>
>> ldap_close($ds);
>> <<<
>>
>> I get following error:
>> Warning: ldap_sort() expects parameter 2 to be resource, boolean given
>> in /usr/local/www/data-dist/test/telefonliste/index.php on line 9
>>
>> Warning: ldap_get_entries(): supplied argument is not a valid ldap result
>> resource in /usr/local/www/data-dist/test/telefonliste/index.php on line
>> 10

>
> $sr = @ldap_search($ds,"OU=Benutzergruppen, DC=domain, DC=tld",
> "Company=" . $strCompany);
>
> Here you supress the error by using @.
> I might very well return false or something, because the ldap_search was
> wrong.

As I'm new in PHP I didn't know about @. Now I removed it.

> Stop surpressing it, and you'll get more possibly usefull information.
>
> $sr = ldap_sort($ds, $sr, 'givenname');

Now I know what was wrong!
First:
I accidentally wrote ldap_sort twice! *bang-on-head*
Second:
ldap_sort() returns boolean value, which tells us if it was success. Because
of that ldap_get_entries() doesn't get the result of ldap but boolean-value
and thus causes error.

So I have change the following line
$sr = ldap_sort($ds, $sr, 'givenname');
into
ldap_sort($ds, $sr, 'givenname');

Now it works! :)
Thank you!
Floh
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:46 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0