What potential security risks are involved in attempting to retrieve user passwords from an LDAP server in PHP?

When attempting to retrieve user passwords from an LDAP server in PHP, one potential security risk is exposing sensitive information if the connection to the server is not secure. To mitigate this risk, it is important to ensure that the LDAP connection is encrypted using SSL/TLS to protect the transmission of passwords.

// Establish LDAP connection with SSL/TLS encryption
$ldapServer = 'ldaps://ldap.example.com';
$ldapPort = 636;

$ldapConn = ldap_connect($ldapServer, $ldapPort);
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0);

// Bind with the LDAP server using a secure connection
$ldapBind = ldap_bind($ldapConn, $ldapUsername, $ldapPassword);

// Retrieve user passwords securely
// Add your LDAP query code here