mysqli::get_warnings

mysqli_get_warnings

Get result of SHOW WARNINGS

&reftitle.description;

&style.oop;

public ``mysqli_warning``false```mysqli::get_warnings`

&style.procedural;

``mysqli_warning``false```mysqli_get_warnings` `mysqli` `mysql`

Returns a singly linked list comprised of `mysqli_warning` or &false; if there are no warnings. Each object in the list corresponds to a single line from the result of `SHOW WARNINGS`. Calling `mysqli_warning::next` will refill the object with the values from the next row.

To retrieve warning messages, it is recommended to use the SQL command `SHOW WARNINGS [limit row_count]` instead of this function.

The linked list cannot be rewound or retrieved again.

&reftitle.parameters;
&mysqli.link.description;
&reftitle.returnvalues;

Returns a singly linked list comprised of `mysqli_warning` or &false; if there are no warnings.

&reftitle.examples;

### Traversing the linked list to fetch all warnings

&style.oop;

    <?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());
        }
    }

&style.procedural;

    <?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());
        }
    }

&examples.outputs;

    Error number: 1365
    Message: Division by 0
    Error number: 1292
    Message: Truncated incorrect INTEGER value: 'NULL'