PHP mysqli_stmt get_warnings() Method
The PHP mysqli_stmt::get_warnings() / mysqli_stmt_get_warnings() function is used to get result of SHOW WARNINGS.
Syntax
//Object-oriented style public mysqli_stmt::get_warnings() //Procedural style mysqli_stmt_get_warnings(statement)
Parameters
statement |
Required. For procedural style only: Specify a mysqli_stmt object returned by mysqli_stmt_init(). |
Return Value
Returns a mysqli_warning object.
Example: Object-oriented style
The example below shows the usage of mysqli_stmt::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(); } //creating a prepared statement $stmt = $mysqli->stmt_init(); $query = "INSERT INTO Employee SET z = '1'"; $stmt->prepare($query); //executing the SQL statement $stmt->execute(); //getting the warning $warning = $stmt->get_warnings();; //displaying the warning echo "Warning: \n"; print_r($warning); //closing the connection $mysqli->close(); ?>
The output of the above code will be similar to:
Warning: mysqli_warning Object ( [message] => Unknown system variable 'z' [sqlstate] => HY000 [errno] => 1193 )
Example: Procedural style
The example below shows the usage of mysqli_stmt_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(); } //creating a prepared statement $stmt = mysqli_stmt_init($mysqli); $query = "INSERT INTO Employee SET z = '1'"; mysqli_stmt_prepare($stmt, $query); //executing the SQL statement mysqli_stmt_execute($stmt); //getting the warning $warning = mysqli_stmt_get_warnings($stmt);; //displaying the warning echo "Warning: \n"; print_r($warning); //closing the connection mysqli_close($mysqli); ?>
The output of the above code will be similar to:
Warning: mysqli_warning Object ( [message] => Unknown system variable 'z' [sqlstate] => HY000 [errno] => 1193 )
❮ PHP MySQLi Reference