PHP mysqli: get_server_info() function
mysqli_get_server_info() function / mysqli::$server_info
The mysqli_get_server_info() function / mysqli::$server_info returns the MySQL server version.
Syntax:
Object oriented style
string $mysqli->server_info;
Procedural style
string mysqli_get_server_info ( mysqli $link )
Parameter:
Name | Required/Optional | Description |
---|---|---|
connection | Required for procedural style only and Optional for Object oriented style | A link identifier returned by mysqli_connect() or mysqli_init() |
Usage:
mysqli_get_proto_info(connection);
Parameter:
Name | Required/Optional | Description |
---|---|---|
connection | Required | Specifies the MySQL connection to use. |
Return value:
A character string representing the server version.
Version: PHP 5, PHP 7
Example of object oriented style:
<?php
$mysqli = new mysqli("localhost", "user1", "datasoft123");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* print server version */
printf("Server version: %s\n", $mysqli->server_info);
/* close connection */
$mysqli->close();
?>
Output:
Server version: 5.1.36-community-log
Example of procedural style:
<?php
$link = mysqli_connect("localhost", "user1", "datasoft123");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* print server version */
printf("Server version: %s\n", mysqli_get_server_info($link));
/* close connection */
mysqli_close($link);
?>
Output:
Server version: 4.1.2-alpha-debug
Example:
<?php
$con=mysqli_connect("localhost","user1","datasoft123","hr");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo mysqli_get_server_info($con);
mysqli_close($con);
?>
Output:
5.1.36-community-log
See also
Previous: protocol_version
Next: server_version
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/php/function-reference/mysqli_server_info.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics