Easy Tutorial
❮ Php Mysql Insert Multiple Func Curl_Pause ❯

PHP mysqli_sqlstate() Function

PHP mysqli Reference Manual

Returns the SQLSTATE error code for the last MySQL operation:

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

// The table websites already exists, so it returns an 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);
?>

Definition and Usage

The mysqli_sqlstate() function returns the SQLSTATE error code for the last error.

The error code consists of five characters. "00000" indicates no error. The values are specified by ANSI SQL and ODBC.


Syntax

Parameter Description
connection Required. Specifies the MySQL connection to use.

Technical Details

Return Value: Returns a string containing the SQLSTATE error code for the last error.
PHP Version: 5+
--- ---
❮ Php Mysql Insert Multiple Func Curl_Pause ❯