PHP Velho Oeste 2024

mysqli::$connect_errno

mysqli_connect_errno

(PHP 5, PHP 7, PHP 8)

mysqli::$connect_errno -- mysqli_connect_errno直近の接続コールに関するエラーコードを返す

説明

オブジェクト指向型

手続き型

mysqli_connect_errno(): int

直近で試みた接続コールに関するエラー番号を返します。

パラメータ

この関数にはパラメータはありません。

戻り値

直近で試みた接続コールが失敗した場合、 エラーコードを返します。ゼロは、何もエラーが発生しなかったことを示します。

例1 $mysqli->connect_errno の例

オブジェクト指向型

<?php

mysqli_report
(MYSQLI_REPORT_OFF);
/* デフォルトのエラーメッセージを抑制するには、@ を使います。 */
$mysqli = @new mysqli('localhost', 'fake_user', 'wrong_password', 'does_not_exist');
if (
$mysqli->connect_errno) {
/* エラーをロギングする方法はお好きなものをどうぞ */
error_log('Connection error: ' . $mysqli->connect_errno);
}

手続き型

<?php

mysqli_report
(MYSQLI_REPORT_OFF);
/* デフォルトのエラーメッセージを抑制するには、@ を使います。 */
$link = @mysqli_connect('localhost', 'fake_user', 'wrong_password', 'does_not_exist');
if (!
$link) {
/* エラーをロギングする方法はお好きなものをどうぞ */
error_log('Connection error: ' . mysqli_connect_errno());
}

参考

add a note add a note

User Contributed Notes 2 notes

up
6
Daro AP
9 years ago
'errmsg.h' and 'mysqld_error.h' files only have the definitions of the error codes. In the MySQL documentation you can find the definition along with the message it displays, which could be more useful since the error constant name isn't always explicit enough.

Client Error Codes and Messages
http://dev.mysql.com/doc/refman/5.6/en/error-messages-client.html

Server Error Codes and Messages
http://dev.mysql.com/doc/refman/5.6/en/error-messages-server.html
up
-7
till at etill dot net
8 years ago
As of 5.5.9, connect_errno will not show an error if the host or the user (or both) are empty strings, so such cases have to be accounted for separately.
To Top