PHP mysqli_sqlstate() Function

Definition

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

Syntax

PHP mysqli_sqlstate() Function has the following syntax.

mysqli_sqlstate(connection);

Return

The error code consists of five characters. "00000" indicates no error.

The values are specified by ANSI SQL.

Example


<?php// w ww .j  a v  a  2 s.  c om
    $con=mysqli_connect("localhost","my_user","my_password","my_db");
    if (mysqli_connect_errno($con)){
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
    $sql="CREATE TABLE Persons (Firstname VARCHAR(30),Lastname VARCHAR(30),Age INT)";
    if (!mysqli_query($con,$sql)){
      echo "SQLSTATE error: ". mysqli_sqlstate($con);
    }
    
    mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions