ldapsearch returns results, ldap_search() does not.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

ldapsearch returns results, ldap_search() does not.

Post by pickle »

When running an ldapsearch command on the command line, it returns tons of results, whereas an equivalent (or so I think) query via PHP returns nothing.

ldapsearch command:

Code: Select all

 ldapsearch -Zx -H ldap://directory.host.ca -D [CREDENTIALS] -w [PASSWORD] -z 0 -l 0 - LLL -b "ou=people,dc=business,dc=ca" "(&(facultyCode=AU)(term=1380)" uid
PHP search:

Code: Select all

    //binding has already happened with the same credentials as used in the CLI command
    $filter = '(&(facultyCode=AU)(term="1380"))';
    $list   = ldap_search($conn,'ou=people,dc=business,dc=ca',$filter,array('uid'),0,0,0);
What am I missing?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: ldapsearch returns results, ldap_search() does not.

Post by Benjamin »

Never used ldap. But I've run into issues where the CLI is using a different php.ini file. Anything turn up in error logs?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: ldapsearch returns results, ldap_search() does not.

Post by pickle »

The CLI isn't using PHP at all. It's a direct OpenLDAP executable. The person that's helping me with this is using raw command line calls - I'm just trying to get my PHP code to give me the same results.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: ldapsearch returns results, ldap_search() does not.

Post by Benjamin »

User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: ldapsearch returns results, ldap_search() does not.

Post by pickle »

Thanks for that, but it doesn't really apply to me. I'm not getting an error. I'm getting a successful search result - just with zero records. If I change my filter to ask for, say, all users - I get expected results. I'm fairly certain my problem is that my filter - as seen by the ldap server - is different between the PHP call, and the raw ldapsearch CLI command.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply