Re: New Bie DB_ldap help

From: Date: Sat, 08 Oct 2005 17:45:39 +0000
Subject: Re: New Bie DB_ldap help
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-21289@lists.php.net to get a copy of this message
On 10/8/05, Ramdas Phutane <ramdas.phutane@gmail.com> wrote: > Hi Group, > > I am want some help with DB_ldap. > > I want to do a ldap_connect -> ldap_search -> print result using > DB_ldap. But I am not able to get any example code for this. > > Could any one please help me. > > My code (not working ) > -------------- > <? > require_once ('DB/ldap.php') ; > require_once 'DB/common.php'; You shouldn't ever need to include DB/common.php. In fact you never need to include any DB/* files. Just: require_once('DB.php'); > > $params = array ( > 'username' => 'cn=root,c=IN' , > 'password' => 'pass', > 'hostspec' => 'localhost', > 'database' => 'c=IN' > ) ; > > $db = new DB_ldap ; > # To Connect > $db->connect($params) ; Don't do it that way. $db =& DB::connect($params); > if (PEAR::isError($db)) { > die($db->getMessage()); > } > # To perform query > $res = $db->simpleQuery('cn=man*','search',$params) ; > $res1 = $db->query('cn=man*','search',$params) ; Why are you querying twice? Only use query(), not simpleQuery(). > # RND, I am not sure how to display results > echo $res ; > var_dump ($res1) ; > echo '<br>'; > echo $res1 ; query() returns a result. You don't want to output that. > > echo '<br>'; > $result = $db->getRow($res1) ; > echo $result ; > echo 'Hello<br>' ; > ?> You need to read the DB manual. while ($row = $res1->fetchRow()) { //you may want DB_FETCHMODE_ASSOC print_r($row); } -- Justin Patrin

« previous php.pear.general (#21289) next »