PHP mysqli_sqlstate() Function

PHP mysqli_sqlstate() function returns the SQLSTATE error code from the previous MySQL operation.


string mysqli_sqlstate(connection);

mysqli_sqlstate() Function Parameter

connection :Required parameter. The MySQL connection to be used

mysqli_sqlstate() Function Return Value

Return Values :Returns a string containing the SQLSTATE error code for the last error.

mysqli_sqlstate() Function Example

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

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

$sql = "CREATE TABLE employee (fname VARCHAR(150), lname VARCHAR(230))";

// 'employee' table already exists
if (!mysqli_query($con, $sql)) {
    echo "SQLSTATE Error : ". mysqli_sqlstate($con);