Jump to content

Advice on Database Query..


TomT

Recommended Posts

Hi

I'm using a couple of queries to search a database.

This works well but is slow as I'm cascading/nesting the queries..

 

Below is an example of what I mean... (LDAP queries)

Code:

 

<?
   $dn = "cn=user";
	   $filter="(objectclass=user)";
	   $justthese = array('cn','telephone','guid','ID','email');
	   $sr=ldap_search($ds, $dn, $filter, $justthese);
	   $info = ldap_get_entries($ds, $sr);
       		for ($n=0; $n<$info['count']; $n++) {				
			$cn = $info[$n]['cn'][0];
			$email = $info[$n]['email'][0];
			$id= $info[$n]['id'][0];

   $dn = "cn=Device";
	   $filter="(objectclass=device)(userid=$id)";
	   $justthese = array('cn','system','guid','ID','userid');
	   $sr=ldap_search($ds, $dn, $filter, $justthese);
	   $info = ldap_get_entries($ds, $sr);
       		for ($n=0; $n<$info['count']; $n++) {				
			$system = $info[$n]['system'][0];
			$userid = $info[$n]['userid'][0];

   	}		
      } 
?>

I'm sure there's a better way of writing this... that will make it faster.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/248332-advice-on-database-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.