php8.5
Home/ Manual/ ldap / functions/ ldap_errno

ldap_errno

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Return the LDAP error number of the last LDAP command

Description

ldap_errno(LDAP\Connection $ldap): int

Returns the standardized error number returned by the last LDAP command. This number can be converted into a textual error message using ldap_err2str().

Parameters

ldap

Ldap

Return Values

Return the LDAP error number of the last LDAP command for this link.

Changelog

VersionDescription

Examples

Unless you lower your warning level in your Ini sufficiently or prefix your LDAP commands with @ (at) characters to suppress warning output, the errors generated will also show up in your HTML output.

Generating and catching an error

php
<?php
// This example contains an error, which we will catch.
$ld = ldap_connect("localhost");
$bind = ldap_bind($ld);
// syntax error in filter expression (errno 87),
// must be "objectclass=*" to work.
$res =  @ldap_search($ld, "o=Myorg, c=DE", "objectclass");
if (!$res) {
    echo "LDAP-Errno: " . ldap_errno($ld) . "<br />\n";
    echo "LDAP-Error: " . ldap_error($ld) . "<br />\n";
    die("Argh!<br />\n");
}
$info = ldap_get_entries($ld, $res);
echo $info["count"] . " matching entries.<br />\n";
?>

See Also

Source: reference/ldap/functions/ldap-errno.xml · from the official PHP manual (php/doc-en)