PHP mysqli_warning_count() Function

PHP mysqli_warning_count() function returns the number of warnings from the last query in the connection.

Syntax

int mysqli_warning_count(connection);

mysqli_warning_count() Function Parameter

ParameterDescription
connection :Required parameter. The MySQL connection to be used

mysqli_warning_count() Function Return Value

Return Values :Number of warnings or zero if there are no warnings.

mysqli_warning_count() Function Example

<?php
$con = mysqli_connect("localhost","user","password","db");

if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con, "CREATE TABLE employee LIKE emp");

// long last name in lname
$query = "INSERT INTO employee (fname, lname) VALUES('James',
        'fdfkdjf dsf fsdfsdfdsfjsfdsdf;ldfsdfjsdfjfsdfsdfsdfdf sdf sdf f sdf sdf f sf')";

mysqli_query($con, $query);

if (mysqli_warning_count($con)) {
    if ($result = mysqli_query($con, "SHOW WARNINGS")) {
        $row = mysqli_fetch_row($result);
        echo $row[0]. " " . $row[1]. " " . $row[2];
        mysqli_free_result($result);
    }
}
mysqli_close($con);
?>