Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching MySql results with LDAP results?

Status
Not open for further replies.

mns76

Technical User
Aug 6, 2004
2
US
I am lost in this. Is it possible to match the results from a query in php/mysql to the results from php/openldap?

My AD has the needed email addresses, while the MySql has the needed survey results.

Both have one common field: "username"

Basically I need to match them up, and of course not everyone will need to be matched, only those people who submitted a survey to the MySql database. And it would be nice to see the results on one webpage.

Any help would be appreciated, as I am stumped on how to match these results.

So, below is the code for both sides: MYSQL & AD

--------------------------- MYSQL --------------------------

<?
include('includes/configure.php');
$sql = mysql_query("SELECT * FROM results"); // Perform MySQL query on only the current page number's results
?>

<html>
<head>
<title>survey</title>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" valign="top"><table width="100%" border="0">
<tr>
<td>INCIDENT</td>
<td>REQUESTOR</td>
<td>REQUESTOR email</td>
<td>SUBJECT</td>
<td>DATE SUBMITTED</td>
<td class="nicetableheader">DATE CLOSED</td>
</tr>
<?
while ($row = mysql_fetch_array($sql)) {
$username= $row['username'];
$subject= $row['subject'];
?>
<tr>
<td class="nicetablerow"><?php echo $username; ?></td>
<td class="nicetablerow"><?php echo $subject; ?></td>
</tr>
<? } ?>



</table>
</td></tr></table>
</body>
</html>


--------------------------------------AD -----------------

<html>
<head>
<title>
User Information Look Up
</title>
</head>
<body>
<h1>User Information Look Up
</h1>
<?
$ldapserver=ldap_connect("myserver");
if(!$ldapserver)
{
print "System Error";
exit(0);
}
$bind = ldap_bind($ldapserver,"cn=XXX,cn=XXX,dc=XXX,dc=com","XXXXXXXX");
if(!bind)
{
print "System Error";
exit(0);
}
$base_dn = "DC=XXX,DC=com";

$filter = "sn=*";


$inforequired = array(
"username",
"description",
"mail",
"givenName",
"sn",
"cn");

$result = ldap_search($ldapserver,$base_dn,$filter,$inforequired);
$info = ldap_get_entries($ldapserver,$result);

if($info["count"] == 0)
{
print "<p>No information available";
}
else
{ ?>
<table border=2>
<tr>
<td>First name</td>
<td>Surname</td>
<td>Full Name</td>
<td>Department</td>
<td>Mail</td>
<td>Login</td>
</tr>
<? for($i=0;$i<$info["count"];$i++)
{
$row[$i] = "<tr>"
. "<td>" . $info[$i]["givenname"][0] . "</td>"
. "<td>" . $info[$i]["sn"][0] . "</td>"
. "<td>" . $info[$i]["cn"][0] . "</td>"
. "<td>" . $info[$i]["description"][0] . "</td>"
. "<td>" . $info[$i]["mail"][0] . "</td>"
. "<td>" . $info[$i]["username"][0];

}
sort($row);
for($i=0;$i<$info["count"];$i++) print $row[$i] . "\n";
print "</table>";
}
print "</body></html>";
?>
 
First query the mysql database for all the usernames who have submited the survey. then query that usernames to openldap.

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top