Couple of good error codes to get started. If you want to detect failure of ldap_add due to the record already existing, ldap_error == 0x44. This means, you can do something like:
$r = ldap_add($ds, $dn, $info);
if (!$r) {
if (ldap_errno($ds) == 0x44) {
// Do something about it
} else {
// A real failure
}
}
Similarly, on ldap_delete, you will get a 0x20 value (No Such Object) if you try to delete something that isn't there.