MySQLi - Sqlstate



Syntax

string mysqli_sqlstate ( mysqli $link )

Definition and Usage

It returns the SQLSTATE error from previous MySQL operation.

Example

Try out following example −

<?php
   $servername = "localhost:3306";
   $username = "root";
   $password = "";
   $dbname = "TUTORIALS";
   $conn = new mysqli($servername, $username, $password, $dbname);

   if ($conn->connect_error) {
      die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
      exit();
   } 
   if (!$conn->query("CREATE TABLE tutorials_point (ID INT, Name VARCHAR(30))")) {
      printf("Error - SQLSTATE %s.\n", $mysqli->sqlstate);
   }
?>

The sample output of the above code should be like this −

Errorcode: 0 Success... localhost:3306 via TCP/IP Client library version: 
mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
mysqli_useful_functions.htm
Advertisements