php ldap 排序,PHP ldap_sort 用法 手册 | 示例代码

这篇博客揭示了一个常见误解,即在使用LDAP时,不能像在关系型数据库中那样直接对结果集进行任意字段排序。作者通过代码示例说明,必须在请求的属性中包含用于排序的属性(如'sn'),否则排序不会生效。这提醒了读者, LDAP 的工作方式与RDBMS不同,需要特别注意其特性。
摘要由CSDN通过智能技术生成

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:

// 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...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值