PHP Function Reference

PHP mysqli get_warnings() Method



The PHP mysqli::get_warnings() / mysqli_get_warnings() function is used to get result of SHOW WARNINGS.

Syntax

//Object-oriented style
public mysqli::get_warnings()

//Procedural style
mysqli_get_warnings(mysql)

Parameters

mysql Required. For procedural style only: Specify a mysqli object returned by mysqli_connect() or mysqli_init().

Return Value

Returns a mysqli_warning object.

Example: Object-oriented style

The example below shows the usage of mysqli::get_warnings() method.

<?php
//establishing connection to the database
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
  echo "Failed to connect to MySQL: ". $mysqli->connect_error;
  exit();
}

//executing a SQL query
$result = $mysqli->query("INSERT INTO Employee SET z = '1'");

//getting the warning count
$warning_count = $mysqli->warning_count;

//displaying all warning
if ($warning_count > 0) {
  $e = $mysqli->get_warnings();
  for ($i = 0; $i < $warning_count; $i++) {
    var_dump($e);
    $e->next();
  }
}

//closing the connection
$mysqli->close();
?>

Example: Procedural style

The example below shows the usage of mysqli_get_warnings() function.

<?php
//establishing connection to the database
$mysqli = mysqli_connect("localhost", "user", "password", "database");
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: ". mysqli_connect_error();
  exit();
}

//executing a SQL query
$result = mysqli_query($mysqli, "INSERT INTO Employee SET z = '1'");

//getting the warning count
$warning_count = mysqli_warning_count($mysqli);

//displaying all warning
if ($warning_count > 0) {
  $e = mysqli_get_warnings($mysqli);
  for ($i = 0; $i < $warning_count; $i++) {
    var_dump($e);
    $e->next();
  }
}

//closing the connection
mysqli_close($mysqli);
?>

❮ PHP MySQLi Reference