ldap_modify在函数中不起作用,引发“对象类冲突”错误

时间:2019-08-14 11:45:35

标签: php ldap

我创建了一个php代码,用于更新AD中用户的电子邮件。可以了!
但是我想在函数中编写代码。当我编写与函数相同的代码时,ldap_modify会引发"Object class violation"错误。

对不起,我的英语不好!

我检查了函数之前和函数中的所有变量,一切似乎正常。否则我是盲人,看不到错误。

此代码有效,并且电子邮件已在AD中更新

$entry["mail"] = 'foo@bar.com';
$result = ldap_modify($ldap->getLdap_connection(), $user_dn, $entry);
if ($result === false) {
   echo 'error';
}else{
   echo 'OK';
}

但是,当代码作为函数编写时,代码会引发"Object class violation"错误。


function update_field($connection, $dn, $entry, $debug){
    $error = array();
    $result = NULL;

    if($connection === NULL){
       $error[] = 'LDAP connection is NULL'; 
    }

    if($dn === NULL){
       $error[] = 'User DN is NULL';
    }

    if($entry === NULL){
      $error[] = 'Field is NULL'; 
    }

    if($debug){ }        

    if(empty($error)){
        $result = ldap_modify($connection, $dn, $entry);        
        if($result === false) {
            $result = ldap_error($connection);
        }else{
            $result = 'OK';
        }
    }else{
        $result = $error;
    }
    return $result;
}

$entry["mail"] = 'foo@bar.com';
$update =  update_field($ldap->getLdap_connection(), $dn, $entry, 1); 

0 个答案:

没有答案