w3resource

PHP mysqli: get_warnings() function

mysqli_get_warnings function / mysqli::get_warnings

The mysqli_get_warnings function / mysqli::get_warnings — get result of SHOW WARNINGS

Syntax:

Object oriented style

mysqli_warning mysqli::get_warnings ( void )

Procedural style

mysqli_warning mysqli_get_warnings ( mysqli $link )

Usage: Procedural style

mysqli_get_warnings ( void );

Parameter:

Name Description Required/Optional
connection Specifies the MySQL connection to use. Required

Return value:

Returns an array with connection stats if success, FALSE otherwise.

Version: PHP 5 >= 5.1.0, PHP 7

Example of object oriented style:

<?php
$r = mysqli_query($db, "INSERT INTO blah SET z = '1'"); 
$j = mysqli_warning_count($db); 
if ($j > 0) { 
    $e = mysqli_get_warnings($db); 
    for ($i = 0; $i < $j; $i++) { 
        var_dump($e); 
        $e->next(); 
    } 
} 
?>

Example:

<?php
$r = mysqli_query($con, "INSERT INTO blah SET z = '1'"); 
$j = mysqli_warning_count($con); 
	if ($j > 0) { 
    $e = mysqli_get_warnings($con); 
    for ($i = 0; $i < $j; $i++) { 
        var_dump($e); 
        $e->next(); 
    } 
} 
?>

See also

PHP Function Reference

Previous: server_version
Next: info



Follow us on Facebook and Twitter for latest update.

PHP: Tips of the Day

Getting all defined constants

To get all defined constants including those created by PHP use the get_defined_constants function:

Example:

<?php
$constants = get_defined_constants();
var_dump($constants); // pretty large list

Output:

array(2250) {
  ["E_ERROR"]=>
  int(1)
  ["E_RECOVERABLE_ERROR"]=>
  int(4096)
  ["E_WARNING"]=>
  .....
  .....
  resource(1) of type (stream)
  ["STDOUT"]=>
  resource(2) of type (stream)
  ["STDERR"]=>
  resource(3) of type (stream)
}

To get only those constants that were defined by your app call the function at the beginning and at the end of your script (normally after the bootstrap process):

<?php
$constants = get_defined_constants();
define("HELLO", "hello");
define("WORLD", "world");
$new_constants = get_defined_constants();
$myconstants = array_diff_assoc($new_constants, $constants);
var_export($myconstants);

Output:

array (
  'HELLO' => 'hello',
  'WORLD' => 'world',
)

It's sometimes useful for debugging

 





We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook