Returns the SQLSTATE error code of the last MySQL operation:
<?php // Assume database username: root, password: 123456, database: CODERCTO $con=mysqli_connect("localhost","root","123456","CODERCTO"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Data table websites already exists, so the error $sql="CREATE TABLE websites (name VARCHAR(30),url VARCHAR(30),alexa INT)";if (!mysqli_query($con,$sql)){ echo "SQLSTATE error: " . mysqli_sqlstate($con);}//Close the connection mysqli_close($con);?>
The mysqli_sqlstate() function returns the SQLSTATE error code of the last error.
The error code contains five characters. "00000" indicates no errors. Values are specified by ANSI SQL and ODBC.
mysqli_sqlstate( connection ) ;
parameter | describe |
---|---|
connection | Required. Specifies the MySQL connection to use. |
Return value: | Returns a string containing the SQLSTATE error code of the last error. |
---|---|
PHP version: | 5+ |