PHP 8.3.4 Released!

mysqli::$errno

mysqli_errno

(PHP 5, PHP 7, PHP 8)

mysqli::$errno -- mysqli_errno直近の関数コールによるエラーコードを返す

説明

オブジェクト指向型

手続き型

mysqli_errno(mysqli $mysql): int

直近の MySQLi 関数のコールが成功あるいは失敗した際のエラーコードを返します。

パラメータ

link

手続き型のみ: mysqli_connect() あるいは mysqli_init() が返す mysqliオブジェクト。

戻り値

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

例1 $mysqli->errno の例

オブジェクト指向型

<?php
$mysqli
= new mysqli("localhost", "my_user", "my_password", "world");

/* 接続状況をチェックします */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}

if (!
$mysqli->query("SET a=1")) {
printf("Errorcode: %d\n", $mysqli->errno);
}

/* 接続を閉じます */
$mysqli->close();
?>

手続き型

<?php
$link
= mysqli_connect("localhost", "my_user", "my_password", "world");

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

if (!
mysqli_query($link, "SET a=1")) {
printf("Errorcode: %d\n", mysqli_errno($link));
}

/* 接続を閉じます */
mysqli_close($link);
?>

上の例の出力は以下となります。

Errorcode: 1193

参考

add a note

User Contributed Notes 1 note

up
21
erwin at transpontine dot com
10 years ago
You can also find the error codes for for example MySQL 5.5 here: http://dev.mysql.com/doc/refman/5.5/en/error-handling.html
To Top