TechniqueUse the ldap_free_result() function to free result sets: <?php // Open and bind a connection $lh = ldap_connect("localhost") or die("Cannot connect to LDAP"); ldap_bind($lh) or die("Cannot Bind"); // criteria $bdn = "o=Sterling's Company, c=US"; $criteria = array("ou"); // perform query and free result $sth = ldap_list($lh, $bdn, "ou=*", $criteria); $data = ldap_get_entries($lh, $sth); ldap_free_result($sth); // loop through results while ($idx < $data["count"]) { print $data[$idx++]["ou"][0] . "\n<br>\n"; } // close the connection ldap_unbind($lh); ?> CommentsThe ldap_free_result() function simply takes a handle of a result set and frees the memory allocated internally for that result set. In this example, we search the current level ( ldap_list() ) with our criteria, and then get the results and put them into a variable (which happens to be an array because that is what ldap_get_entries() returns). Then we free the result set because it is no longer needed. With the advent of PHP4 and Zend's garbage collection feature, ldap_free_result() might seem redundant. However, for backward compatibility and for good programming practices, it is best to free result sets explicitly. |