PHP: Hypertext Preprocessor (original) (raw)
ldap_errno
(PHP 4, PHP 5, PHP 7, PHP 8)
ldap_errno — Return the LDAP error number of the last LDAP command
Description
Return Values
Return the LDAP error number of the last LDAP command for this link.
Changelog
Version | Description |
---|---|
8.1.0 | The ldap parameter expects an LDAP\Connection instance now; previously, a valid ldap link resource was expected. |
Examples
Unless you lower your warning level in your php.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.
Example #1 Generating and catching an error
<?php // This example contains an error, which we will catch. $ld = ldap_connect("localhost"); <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>b</mi><mi>i</mi><mi>n</mi><mi>d</mi><mo>=</mo><mi>l</mi><mi>d</mi><mi>a</mi><msub><mi>p</mi><mi>b</mi></msub><mi>i</mi><mi>n</mi><mi>d</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">bind = ldap_bind(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">bin</span><span class="mord mathnormal">d</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mord mathnormal">a</span><span class="mord"><span class="mord mathnormal">p</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal">in</span><span class="mord mathnormal">d</span><span class="mopen">(</span></span></span></span>ld); // syntax error in filter expression (errno 87), // must be "objectclass=*" to work. <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mo>=</mo><mi mathvariant="normal">@</mi><mi>l</mi><mi>d</mi><mi>a</mi><msub><mi>p</mi><mi>s</mi></msub><mi>e</mi><mi>a</mi><mi>r</mi><mi>c</mi><mi>h</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">res = @ldap_search(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">res</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">@</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mord mathnormal">a</span><span class="mord"><span class="mord mathnormal">p</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">s</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal">e</span><span class="mord mathnormal">a</span><span class="mord mathnormal">rc</span><span class="mord mathnormal">h</span><span class="mopen">(</span></span></span></span>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"); } <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mi>n</mi><mi>f</mi><mi>o</mi><mo>=</mo><mi>l</mi><mi>d</mi><mi>a</mi><msub><mi>p</mi><mi>g</mi></msub><mi>e</mi><msub><mi>t</mi><mi>e</mi></msub><mi>n</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>e</mi><mi>s</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">info = ldap_get_entries(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">in</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">o</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.0361em;vertical-align:-0.2861em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mord mathnormal">a</span><span class="mord"><span class="mord mathnormal">p</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.03588em;">g</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mord mathnormal">e</span><span class="mord"><span class="mord mathnormal">t</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">e</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal">n</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">i</span><span class="mord mathnormal">es</span><span class="mopen">(</span></span></span></span>ld, $res); echo $info["count"] . " matching entries.<br />\n"; ?>
See Also
- ldap_err2str() - Convert LDAP error number into string error message
- ldap_error() - Return the LDAP error message of the last LDAP command
Found A Problem?
23 years ago
`Couple of good error codes to get started. If you want to detect failure of ldap_add due to the record already existing, ldap_error == 0x44. This means, you can do something like:
r=ldapadd(r = ldap_add(r=ldapadd(ds, dn,dn, dn,info);
if (!$r) {
if (ldap_errno($ds) == 0x44) {
// Do something about it
} else {
// A real failure
}
}
Similarly, on ldap_delete, you will get a 0x20 value (No Such Object) if you try to delete something that isn't there.
`
23 years ago
`Common LDAP error codes
LDAP_SUCCESS 0x00
LDAP_OPERATIONS_ERROR 0x01
LDAP_PROTOCOL_ERROR 0x02
LDAP_TIMELIMIT_EXCEEDED 0x03
LDAP_SIZELIMIT_EXCEEDED 0x04
LDAP_COMPARE_FALSE 0x05
LDAP_COMPARE_TRUE 0x06
LDAP_AUTH_METHOD_NOT_SUPPORTED 0x07
LDAP_STRONG_AUTH_REQUIRED 0x08
// Not used in LDAPv3
LDAP_PARTIAL_RESULTS 0x09
// Next 5 new in LDAPv3
LDAP_REFERRAL 0x0a
LDAP_ADMINLIMIT_EXCEEDED 0x0b
LDAP_UNAVAILABLE_CRITICAL_EXTENSION 0x0c
LDAP_CONFIDENTIALITY_REQUIRED 0x0d
LDAP_SASL_BIND_INPROGRESS 0x0e
LDAP_NO_SUCH_ATTRIBUTE 0x10
LDAP_UNDEFINED_TYPE 0x11
LDAP_INAPPROPRIATE_MATCHING 0x12
LDAP_CONSTRAINT_VIOLATION 0x13
LDAP_TYPE_OR_VALUE_EXISTS 0x14
LDAP_INVALID_SYNTAX 0x15
LDAP_NO_SUCH_OBJECT 0x20 /* 32 */
LDAP_ALIAS_PROBLEM 0x21
LDAP_INVALID_DN_SYNTAX 0x22
// Next two not used in LDAPv3
LDAP_IS_LEAF 0x23
LDAP_ALIAS_DEREF_PROBLEM 0x24
LDAP_INAPPROPRIATE_AUTH 0x30 /* 48 /
LDAP_INVALID_CREDENTIALS 0x31 / 49 */
LDAP_INSUFFICIENT_ACCESS 0x32
LDAP_BUSY 0x33
LDAP_UNAVAILABLE 0x34
LDAP_UNWILLING_TO_PERFORM 0x35
LDAP_LOOP_DETECT 0x36
LDAP_SORT_CONTROL_MISSING 0x3C /* 60 /
LDAP_INDEX_RANGE_ERROR 0x3D / 61 */
LDAP_NAMING_VIOLATION 0x40
LDAP_OBJECT_CLASS_VIOLATION 0x41
LDAP_NOT_ALLOWED_ON_NONLEAF 0x42
LDAP_NOT_ALLOWED_ON_RDN 0x43
LDAP_ALREADY_EXISTS 0x44 /* 68 */
LDAP_NO_OBJECT_CLASS_MODS 0x45
LDAP_RESULTS_TOO_LARGE 0x46
// Next two for LDAPv3
LDAP_AFFECTS_MULTIPLE_DSAS 0x47
LDAP_OTHER 0x50
// Used by some APIs
LDAP_SERVER_DOWN 0x51
LDAP_LOCAL_ERROR 0x52
LDAP_ENCODING_ERROR 0x53
LDAP_DECODING_ERROR 0x54
LDAP_TIMEOUT 0x55
LDAP_AUTH_UNKNOWN 0x56
LDAP_FILTER_ERROR 0x57 /* 87 */
LDAP_USER_CANCELLED 0x58
LDAP_PARAM_ERROR 0x59
LDAP_NO_MEMORY 0x5a
// Preliminary LDAPv3 codes
LDAP_CONNECT_ERROR 0x5b
LDAP_NOT_SUPPORTED 0x5c
LDAP_CONTROL_NOT_FOUND 0x5d
LDAP_NO_RESULTS_RETURNED 0x5e
LDAP_MORE_RESULTS_TO_RETURN 0x5f
LDAP_CLIENT_LOOP 0x60
LDAP_REFERRAL_LIMIT_EXCEEDED 0x61
`