mysqli::$error

mysqli_error

(PHP 5, PHP 7, PHP 8)

mysqli::$error -- mysqli_error直近のエラーの内容を文字列で返す

説明

オブジェクト指向型

手続き型

mysqli_error(mysqli$mysql): string

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

パラメータ

link

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

戻り値

エラーの内容を表す文字列を返します。エラーが発生しなかった場合は空文字列を返します。

例1 $mysqli->error の例

オブジェクト指向型

<?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("Error message: %s\n", $mysqli->error);
}


$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("Error message: %s\n", mysqli_error($link));
}


mysqli_close($link);
?>

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

Error message: Unknown system variable 'a'

参考

To Top