...

View Full Version : ldap information to mysql



ravin
03-15-2007, 09:01 PM
Hello!

Is it possible to use this printed code to import the data into mysql? the sql query code is something that already exists in my system. Any help would be appriciated.

LDAP CODE


..
..
..
$number_returned = ldap_count_entries($connect,$search);
$info = ldap_get_entries($connect, $search);

echo "The number of users returned are : ". $number_returned."<p>";

for ($i=0; $i<$info["count"]; $i++) {
echo "<b>Company :</b> ". $info[$i]["company"][0]."<br>";
echo "<b>Title :</b> ". $info[$i]["title"][0]."<br>";
echo "<b>Department :</b> ". $info[$i]["department"][0]."<br>";
echo "<b>Username :</b> ". $info[$i]["samaccountname"][0]."<br>";
echo "<b>Firstname :</b> ". $info[$i]["givenname"][0]."<br>";
echo "<b>Lastname :</b> ". $info[$i]["sn"][0]."<br>";
echo "<b>Fullname :</b> ". $info[$i]["cn"][0]."<br>";
echo "<b>Display name :</b> ". $info[$i]["displayname"][0]."<br>";
echo "<b>Email :</b> ". $info[$i]["mail"][0]."<br>";
echo "<b>Telephone number :</b> ". $info[$i]["telephonenumber"][0]."<br>";
echo "<b>Home number :</b> ". $info[$i]["homephone"][0]."<br>";
echo "<b>Mobile number :</b> ". $info[$i]["mobile"][0]."<br>";
echo "<b>Street :</b> ". $info[$i]["streetaddress"][0]."<br>";
echo "<b>Postalcode :</b>". $info[$i]["postalcode"][0]."<br>";
echo "<b>City :</b> ". $info[$i]["l"][0]."<br>";
echo "<b>Country :</b> ". $info[$i]["co"][0]."<br>";
echo "<b>Member of :</b> ". $info[$i]["memberof"][0]."<br>";
echo "<b>Last Change :</b> ". $info[$i]["whenchanged"][0]."<p>";



SQL Database Query


..
..

//Get a count of any existing records in the userdb
$conDb_sw1->Query("select count(keysearch) count from userdb where keysearch = '".$employee_name."'");
$conDb_sw1->Fetch("user");

if ( $user_count > 0)
{
//If emp_no exists, then do an update
$udsql = "update userdb set ";
$udsql .= "firstname = '".str_replace ("'", "\'",$employee_first)."', ";
$udsql .= "surname = '".str_replace ("'", "\'",$employee_surname)."', ";
$udsql .= "email = '".str_replace ("'", "\'",$employee_email)."', ";
$udsql .= "telext = '".str_replace ("'", "\'",$employee_telext)."', ";
$udsql .= "mobiletel = '".str_replace ("'", "\'",$employee_mobile)."', ";
$udsql .= "faxtel = '".str_replace ("'", "\'",$employee_fax). "' ";
$udsql .= "where keysearch = ".$employee_name."'";

if(!$conDb_sw2->Query($udsql))
{
//If not, write to log with warning.
logwrite($fp, $employee_name."...".$employee_email." was not updated", "[WARN ]");
logwrite($fp, " SQL for last error " . $udsql);
}

}
else
{
//If the count was 0, then record does not exist so do an insert.
$insql = "insert into userdb (keysearch, firstname, surname, costcenter, site, email, telext, mobiletel, faxtel) ";
$insql .= "values (";
$insql .= "'".str_replace ("'", "\'", $employee_name)."', ";
$insql .= "'".str_replace ("'", "\'", $employee_first)."', ";
$insql .= "'".str_replace ("'", "\'", $employee_surname)."', ";
$insql .= "'Unknown Costcenter', ";
$insql .= "'Unknown Site', ";
$insql .= "'".str_replace ("'", "\'", $employee_email)."', ";
$insql .= "'".str_replace ("'", "\'", $employee_telext)."', ";
$insql .= "'".str_replace ("'", "\'", $employee_mobile)."', ";
$insql .= "'".str_replace ("'", "\'", $employee_fax)."')";

if(!$conDb_sw2->Query($insql))
{
logwrite($fp, $employee_name."...".$employee_email." was not inserted", "[WARN ]");
logwrite($fp, " SQL for last error " . $insql);
}

}
}
logwrite($fp, " >>>>>> Update of the userdb Table now complete");
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum