mysqli::get_warnings

mysqli_get_warnings

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

mysqli::get_warnings -- mysqli_get_warningsLee el resultado de SHOW WARNINGS

Descripción

Estilo orientado a objetos

public mysqli::get_warnings(): mysqli_warning|false

Estilo por procedimientos

mysqli_get_warnings(mysqli $mysql): mysqli_warning|false

Devuelve una lista simplemente enlazada compuesta de mysqli_warning o false si no hay advertencias. Cada objeto de la lista corresponde a una línea única del resultado de SHOW WARNINGS. Llamar a mysqli_warning::next() rellenará el objeto con los valores de la línea siguiente.

Nota: Para recuperar los mensajes de advertencia, se recomienda utilizar el comando SQL SHOW WARNINGS [LIMIT row_count] en lugar de esta función.

Advertencia

La lista enlazada no puede ser reinicializada ni recuperada nuevamente.

Parámetros

link

Sólo estilo por procediminetos: Un identificador de enlace devuelto por mysqli_connect() o mysqli_init()

Valores devueltos

Devuelve una lista simplemente enlazada compuesta de mysqli_warning o false si no hay advertencias.

Ejemplos

Ejemplo #1 Recorrer la lista enlazada para recuperar todas las advertencias

Estilo orientado a objetos

<?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("Número de error: %s\n", $warning->errno);
printf("Mensaje: %s\n", $warning->message);
} while (
$warning->next());
}
}

El resultado de los ejemplos sería:

Número de error: 1365
Mensaje: División por 0
Número de error: 1292
Mensaje: Valor INTEGER incorrecto truncado: 'NULL'
add a note

User Contributed Notes 1 note

up
9
Anonymous
11 years ago
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.
To Top