array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'mysqli.error.php', 1 => 'mysqli::$error', ), 'up' => array ( 0 => 'class.mysqli.php', 1 => 'mysqli', ), 'prev' => array ( 0 => 'mysqli.error-list.php', 1 => 'mysqli::$error_list', ), 'next' => array ( 0 => 'mysqli.execute-query.php', 1 => 'mysqli::execute_query', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/mysqli/mysqli/error.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
mysqli::$error -- mysqli_error — 直近のエラーの内容を文字列で返す
オブジェクト指向型
手続き型
直近の 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'