大网数据广告活动
PHP 语言与运行手册

mysqli::get_warnings · Get result of SHOW WARNINGS

· 52CE 我爱测

mysqli::get_warnings -- mysqli_get_warnings — Get result of SHOW WARNINGS

mysqli::get_warnings

mysqli_get_warnings

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

mysqli::get_warnings -- mysqli_get_warnings — Get result of SHOW WARNINGS

说明

面向对象风格

public function mysqli::get_warnings(): mysqli_warning|false

过程化风格

function mysqli_get_warnings(mysqli $mysql): mysqli_warning|false

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.

参数

mysql

仅以过程化样式:由 mysqli_connect() 或 mysqli_init() 返回的 mysqli 对象。

返回值

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

示例

示例 #1 Traversing the linked list to fetch all warnings

面向对象风格

<?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'

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。