PHP 8.3.4 Released!

ldap_error

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

ldap_error直近の LDAP コマンドの LDAP エラーメッセージを返す

説明

ldap_error(LDAP\Connection $ldap): string

指定した ldap に関して、 直近の LDAP コマンドにより生成されたエラーを表すエラーメッセージ文字列を返します。 LDAP errno 番号は標準化されていますが、ライブラリによって異なる (あるいはローカライズされた)エラーメッセージを返します。 エラーメッセージの内容をチェックするのではなく、 必ずエラー番号をチェックするようにしてください。

php.ini で警告レベルを十分に下げるか、 警告出力を抑制するために LDAP コマンドの前に @ 文字をつけない限り、発生したエラーは HTML 出力にも表示されます。

パラメータ

ldap

ldap_connect() が返す LDAP\Connection クラスのインスタンス。

戻り値

エラーメッセージ文字列を返します。

変更履歴

バージョン 説明
8.1.0 引数 ldap は、LDAP\Connection クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、有効な ldap link リソース を期待していました。

参考

  • ldap_err2str() - LDAP のエラー番号をエラーメッセージ文字列に変換する
  • ldap_errno() - 直近の LDAP コマンドの LDAP エラー番号を返す

add a note

User Contributed Notes 2 notes

up
16
Michael Newton
6 years ago
Note that you can sometimes get more detailed error messages by getting the value of the LDAP_OPT_DIAGNOSTIC_MESSAGE option.

For example, after a recent connection error the two gave very different info:

<?php
$conn
= ldap_connect($server);
ldap_search($conn, $dn, $query);

echo
"ldap_error: " . ldap_error($conn);
ldap_get_option($conn, LDAP_OPT_DIAGNOSTIC_MESSAGE, $err);
echo
"ldap_get_option: $err";
?>

This resulted in:

ldap_error: Can't contact LDAP server
ldap_get_option: TLS: hostname does not match CN in peer certificate
up
4
edA-qa at disemia dot com
15 years ago
For those wondering, this function appears to do the same thing as:
<?php
ldap_err2str
( ldap_errno() );
?>
To Top