PHP mysqli_sqlstate() function returns the SQLSTATE error code from the previous MySQL operation.
Syntax
string mysqli_sqlstate(connection);
Parameter | Description |
---|---|
connection : | Required parameter. The MySQL connection to be used |
Return Values : | Returns a string containing the SQLSTATE error code for the last error. |
<?php $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); } mysqli_close($con); ?>