note 44469 added to function.ldap-sort
| From: | zbaizman at yahoo dot com | Date: | Sat, 07 Aug 2004 01:15:43 +0000 |
| Subject: | note 44469 added to function.ldap-sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74113@lists.php.net to get a copy of this message | ||
This note may be self-evident, but the functionality of ldap_sort threw off this sometime user of
relational databases.
The following code will NOT do what you expect:
<?php
// omitted calls to connect and and bind to LDAP server...
// attributes we want to retrieve from LDAP server
$ldap_attributes = array ( 'cn', 'o', 'mail' ) ;
// retrieve attributes from matching entries
$search_results = ldap_search ( $ldap_conn, 'dc=example,dc=org',
'(objectclass=*)', 0, 500, 30 ) ;
// sort entries by last name ('sn')
ldap_sort ( $ldap_conn, $search_results, 'sn' ) ;
?>
The entries will NOT be sorted by last name. Why not? Because LDAP doesn't function like a
RDBMS; you cannot sort a result set on an arbitrary field, regardless of whether you
"selected" it. You must always include the attribute by which you want to sort your
entries among the requested attributes (add 'sn' to $ldap_attributes, in this case).
Hope this is helpful to some other folks who scratched their heads when they tried to sort entries
and it didn't work out...
----
Manual Page -- http://www.php.net/manual/en/function.ldap-sort.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44469
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44469&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44469&report=yes
Search -- http://master.php.net/manage/user-notes.php