Take note:
Calling this function will change the output of mysqli_affected_rows if any warnings are returned. So if you're using mysqli_affected_rows in your application, make sure to call it before calling mysqli_get_warnings.(PHP 5 >= 5.1.0, PHP 7, PHP 8)
mysqli::get_warnings -- mysqli_get_warnings — SHOW WARNINGS の結果を取得する
オブジェクト指向型
手続き型
   mysqli_warning
   で構成された単方向リンクリストを返します。
   警告がない場合は false を返します。
   リスト中のオブジェクトはそれぞれ、
   SHOW WARNINGS の単一行の結果からなります。
   mysqli_warning::next()
   をコールすると、次の行からオブジェクトを埋めます。
  
注意: 警告メッセージを取得するには、 この関数ではなく、SQLコマンド
SHOW WARNINGS [limit row_count]を使うことを推奨します。
リンクリストは、巻き戻したり、再取得したりはできません。
link手続き型のみ: mysqli_connect() あるいは mysqli_init() が返す mysqliオブジェクト。
   mysqli_warning からなる、
   単方向リンクリストを返します。
   警告がない場合は、false を返します。
  
例1 全ての警告を取得するために連結リストを走査する
オブジェクト指向型
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$mysqli->query("SELECT 1/0, CAST('NULL' AS UNSIGNED)");
if ($mysqli->warning_count > 0) {
    $warning = $mysqli->get_warnings();
    if ($warning !== false) {
        do {
            printf("Error number: %s\n", $warning->errno);
            printf("Message: %s\n", $warning->message);
        } while ($warning->next());
    }
}手続き型
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "user", "password", "test");
mysqli_query($link, "SELECT 1/0, CAST('NULL' AS UNSIGNED)");
if (mysqli_warning_count($link) > 0) {
    $warning = mysqli_get_warnings($link);
    if ($warning !== false) {
        do {
            printf("Error number: %s\n", $warning->errno);
            printf("Message: %s\n", $warning->message);
        } while ($warning->next());
    }
}上の例の出力は以下となります。
Error number: 1365 Message: Division by 0 Error number: 1292 Message: Truncated incorrect INTEGER value: 'NULL'
