function connect2db($config)
{
    $ds = @ldap_connect("{$config['ldap_server']}");
    // must be a valid ldap server!
    if ($ds) {
        $r = @da_ldap_bind($ds, $config);
    }
    return $ds;
}
<?php

require_once '../lib/functions.php';
require_once '../lib/ldap/functions.php';
if ($config[ldap_write_server]) {
    $ds = @ldap_connect($config[ldap_write_server]);
} else {
    $ds = @ldap_connect($config[ldap_server]);
}
if ($ds) {
    $r = @da_ldap_bind($ds, $config);
    if ($r) {
        foreach ($show_attrs as $key => $attr) {
            if ($attrmap["{$key}"] == 'none') {
                continue;
            }
            $i = 0;
            $j = -1;
            $name = $attrmap["{$key}"] . $i;
            while (isset(${$name})) {
                $val = ${$name};
                $i++;
                $j++;
                $name = $attrmap["{$key}"] . $i;
                //
                //	if value is the same as the default and the corresponding attribute in ldap does not exist or
                //	the value is the same as that in ldap then continue
                //
                if (check_defaults($val, '', $default_vals["{$key}"]) && !isset($item_vals["{$key}"][$j]) || $val == $item_vals["{$key}"][$j]) {
                    continue;
                }