In this section, two of PHP??™s
LDAP insertion functions are introduced.
Adding a New Entry
You can add new entries to the LDAP directory with the ldap_add() function. Its
prototype follows:
boolean ldap_add(resource link_id, string dn, array entry)
An example follows, although keep in mind this won??™t execute properly because you
don??™t possess adequate privileges to add users to the OpenLDAP directory:
/* Connect and bind to the LDAP server...*/
$dn = "ou=People,dc=OpenLDAP,dc=org";
$entry["displayName"] = "John Wayne";
$entry["company"] = "Cowboys, Inc.";
CHAPTER 17 ?– PHP A ND LDAP 437
$entry["mail"] = "pilgrim@example.com";
ldap_add($connection, $dn, $entry) or die("Could not add new entry!");
ldap_unbind($connection);
?>
Pretty simple, huh? But how would you add an attribute with multiple values?
Logically, you would use an indexed array:
$entry["displayName"] = "John Wayne";
$entry["company"] = "Cowboys, Inc.";
$entry["mail"][0] = "pilgrim@example.com";
$entry["mail"][1] = "wayne.2@example.edu";
ldap_add($connection, $dn, $entry) or die("Could not add new entry!");
Adding to Existing Entries
The ldap_mod_add() function is used to add additional values to existing entries,
returning TRUE on success and FALSE on failure. Its prototype follows:
boolean ldap_mod_add(resource link_id, string dn, array entry)
Revisiting the previous example, suppose that the user John Wayne requested that
another e-mail address be added.
Pages:
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516