Introduction
In this article I describe the PHP MySQLI functions mysqli_sqlstate, mysqli_ssl_set, mysqli_stat, mysqli_stmt_init, mysqli_thread_id and mysqli_thread_safe. To learn some other MySQLI functions, go to:
- MySQLi Function in PHP: Part 1
- MySQLi Function in PHP: Part 2
- MySQLi Function in PHP: Part 3
- MySQLi Function in PHP: Part 4
- MySQLi Function in PHP: Part 5
- MySQLi Function in PHP: Part 6
- MySQLi Function in PHP: Part 7
- MySQLi Function in PHP: Part 8
- MySQLi Function in PHP: Part 9
- MySQLi Function in PHP: Part 10
- MySQLi Function in PHP: Part 11
The PHP MySQLi "mysqli_sqlstate" function returns the SQLSTATE error from a previous MySQL operation or in other words this function returns a string containing the SQLSTATE error code for the last error.
Syntax
| mysqli_sqlstate(connection); |
Parameter of the mysqli_sqlstate function
The parameter of the function is:
| Parameter | Description |
| connection | It specifies the MySQL connection to use. |
Example
An example of the function is:
<?php
$con=mysqli_connect("localhost","root","","mysql");
if(mysqli_connect_errno($con))
{
echo "Unable to connect: ".mysqli_connect_error();
}
$qry="CREATE TABLE Dept (deptid INT,deptName VARCHAR(50),empId INT)"
if(!mysqli_query($con,$qry))
{
echo "SQL STATE error: ".mysqli_sqlstate($con);
}
mysqli_close($con);
?>
Output
PHP mysqli_ssl_set Function
The PHP MySQLi "mysqli_ssl_set" function establishes a secure connection using SSL and this function always returns the true value and if SSL is incorrectly set then it will return an error when you try to connect.
Syntax
| mysqli_ssl_set(connection,key,cert,ca,cipher); |
Parameters of the mysqli_sqlstate function
The parameters of the function are:
| Parameter | Description |
| connection | It specifies the MySQL connection to use. |
| key | It specifies the path name to the key file. |
| cert | It specifies the path name to the certificate file. |
| ca | It specifies the path name to the certificate authority file. |
| cipher | It specifies a list of allowable ciphers to use for SSL encryption. |
Example
An example of the function is:
<?php
$con=mysqli_init();
if (!$con)
{
die("Failed.....");
}
mysqli_ssl_set($con,"key.pem","cert.pem","cacert.pem",NULL,NULL);
if (!mysqli_real_connect($con,"localhost","root","","mysql"))
{
die("Connect Error: " . mysqli_connect_error());
}
//write some PHP code here.
mysqli_close($con);
?>
PHP mysqli_stat() Function
The PHP MySQLi "mysqli_stat" function returns the current system status and this function returns a string that describes the server status or returns false if an error will occur.
Syntax
| mysqli_stat(connection); |
Parameter of the mysqli_stat function
The parameter of the function is:
| Parameter | Description |
| connection | It specifies the MySQL connection to use. |
Example
An example of the function is:
<?php
$con=mysqli_connect("localhost","root","","mysql");
if(mysqli_connect_errno($con))
{
echo "Unable to connect: ".mysqli_connect_error();
}
echo "System status: ".mysqli_stat($con);
mysqli_close($con);
?>
Output



Join the conversation! Your thoughts help the community grow.