Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : LDAP Functions : ldap_mod_del

ldap_mod_del

Delete attribute values from current attributes (PHP 4, PHP 5)
bool ldap_mod_del ( resource link_identifier, string dn, array entry )


Code Examples / Notes » ldap_mod_del

sam_freund

Using ldap_modify with a blank string works if you aren't propagating your LDAP database, even though it returns the error. Still, I'd say don't do it, as it smacks of something that will be fixed in a future version.

ral

To remove all instances of an attribute:
$entry["attrname"][]="value1";
$entry["attrname"][]="value2";
...
$entry["attrname"][]="valueN";
ldap_mod_del($ds, $dn, $entry);


arjanw

To remove all instances of an attribute you can use ldap_modify with an empty value for that attribute.
$entry["mail"] = "";
$result = ldap_modify($connID, $dn, $entry);


joshuastarr

The above example has also been proven to work in the iPlanet / Sun One Directory Server 5.0/5.1. As an example:
$attrs["mail"] = array();
ldap_mod_del($ldapConnID,$dn,$attrs);
or
$attrs["mail"] = array();
$attrs["telephonenumber"] = array();
ldap_mod_del($ldapConnID,$dn,$attrs);
This will remove all occurences of attributes in the entry specified by the dn.


mark

I have found that the syntax:
$entry["mail"] = "";
Will NOT delete the mail attribute using the OpenLDAP server.  You must specify the attribute value to delete it successfully, otherwise you will recieve an "Invalid Syntax" error from the server.
The error: "Inappropriate Matching" will be displayed if the attribute you are trying to delete has no equality rule in the schema.  I had a problem deleting the attribute facsimilieTelephoneNumber, and it was because my core.schema file did not have an EQUALITY definition for that attribute.  I copied the telephoneNumber EQUALITY rule and it worked perfectly.


06-apr-2006 04:35

For anyone interested in removing a user from a group, you can use ldap_mod_del() as follows:
$group = 'CN=mygroup,OU=myOU,DC=mydomain,DC=com';
$group_info['member'] = 'CN=User\, Test,CN=Users,DC=mydomain,DC=com';
ldap_mod_del($ldap, $group, $group_info);
I have tested this using Active Directory on a Win 2K3 server.


ral

At least with OpenLDAP 1.2.x
to remove an attribute regardless of it's value you have to assign:
$attrs["AttributeName"]=array();
after ldap_mod_del($ds,$dn,$attrs)
all occurences of AttributeName will be removed


thomas dot thiel

and please don't forget:
you can't delete all attributes, when at least one is required.


arimus



After a couple hours of searching and not finding anything on the ldap_mod_del function worth anything, I started trying to figure out myself what format the "array entry" parameter needed to be in.  Here is what I found:


The entry array is a hash with the attribute name as the hash key and the specific value you want deleted for that attribute as the corresponding hash value.


<b>Example</b>


Current values for the attributes of of a particular entry:
<pre>
    uid: testuser
    mail: testuser@test.net
    mail: testuser@somewhere.com
</pre>


How to remove the first value of mail so that only the second value for mail exists:
<pre>
    $entry["mail"] = "testuser@test.net";
    $result = ldap_mod_del($connID, $dn, $entry);
</pre>



So if you want to remove all instances of an attribute, you have to do it one by one.


twopairs

<pre>
uid: testuser
mail: testuser@test.net
mail: testuser@somewhere.com
</pre>
How to remove the values of mail so that only the second value for mail exists:
<pre>
$entry["mail"] = "testuser@test.net";
$result = ldap_mod_del($connID, $dn, $entry);
</pre>
if you want to remove all instances of an attribute.....
==>
<pre>
$entry["mail"][0] = "testuser@test.net";
$entry["mail"][1] = "testuser@somewhere.net";
$result = ldap_mod_del($connID, $dn, $entry);
</pre>
are not?


Change Language


Follow Navioo On Twitter
ldap_8859_to_t61
ldap_add
ldap_bind
ldap_close
ldap_compare
ldap_connect
ldap_count_entries
ldap_delete
ldap_dn2ufn
ldap_err2str
ldap_errno
ldap_error
ldap_explode_dn
ldap_first_attribute
ldap_first_entry
ldap_first_reference
ldap_free_result
ldap_get_attributes
ldap_get_dn
ldap_get_entries
ldap_get_option
ldap_get_values_len
ldap_get_values
ldap_list
ldap_mod_add
ldap_mod_del
ldap_mod_replace
ldap_modify
ldap_next_attribute
ldap_next_entry
ldap_next_reference
ldap_parse_reference
ldap_parse_result
ldap_read
ldap_rename
ldap_sasl_bind
ldap_search
ldap_set_option
ldap_set_rebind_proc
ldap_sort
ldap_start_tls
ldap_t61_to_8859
ldap_unbind
eXTReMe Tracker