hi all.....
my script try to do 3 part:
1- get value of all user from active directory 2003
2- store it in table in mysql
3- view the same value in html
first point and third one work perfect but second point not work at all
connect to database work and select table work but insert the array to table in mysql not work at all
i need to know where is the issue
<?php
/**
* @author Phiron
* @copyright 2010
*/
$phpAD_ldap = "ldap://192.168.100.2";
$phpAD_user = "*******";
$phpAD_pass = "*******";
$phpAD_dn = "OU=bad,DC=boy,DC=com,DC=ad";
$error = "";
$attributes = array("displayname", "samaccountname");
$filter = "(!(cn=''))";
$ad = ldap_connect($phpAD_ldap, 389)
or die("Couldn't connect to AD!");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
ldap_get_option($ad,LDAP_OPT_ERROR_STRING,$error);
$bd = ldap_bind($ad,$phpAD_user,$phpAD_pass)
or die("Couldn't bind to AD!");
$result = ldap_search($ad, $phpAD_dn, $filter, $attributes);
$entries = ldap_get_entries($ad, $result);
echo $error;
ldap_unbind($ad);
?>
<html>
<head>
</head>
<body>
<table border="1" align=center>
<tr>
<td align=center>
<big> displayname
</td>
<td align=center>
<big> samaccountname
</td>
</tr>
<?
$con = mysql_connect("localhost","DBAdmin","0123501848");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$sel = mysql_select_db("amaz", $con);
if (!$sel)
{
die('Could not select DB: ' . mysql_error());
}
for ($i=0; $i<$entries["count"]; $i++)
{
$dis = $entries[$i]["displayname"][0];
$sam = $entries[$i]["samaccountname"][0];
mysql_query("INSERT INTO ldap (displayname, samaccountname)
VALUES ('$dis', '$sam')");
}
mysql_close($con);
?>
<?php
for ($i=0; $i<$entries["count"]; $i++)
{
echo '<tr>';
echo '<td>';
echo $entries[$i]["displayname"][0];
echo '</td>';
echo '<td>';
echo $entries[$i]["samaccountname"][0];
echo '</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>