Current Location: Home> Function Categories> mysqli::$server_version

mysqli::$server_version

(mysqli_get_server_version) Returns the version of MySQL server in integer form
Name:mysqli::$server_version
Category:MySQLi
Programming Language:php
One-line Description:Get the version number of the currently connected MySQL server

The function mysqli::$server_version() is a member function of the mysqli class that gets the version number of the currently connected MySQL server.

usage:

 $mysqli = new mysqli("localhost", "username", "password", "database"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: " . $mysqli->connect_error; exit(); } $serverVersion = $mysqli->server_version; echo "MySQL Server Version: " . $serverVersion; $mysqli->close();

Sample output:

 MySQL Server Version: 8.0.21

illustrate:

  • First, create a mysqli object and connect to the MySQL server. If the connection fails, the connection error message will be output and the program will be exited.
  • Get the version number of the currently connected MySQL server by accessing the $mysqli->server_version property.
  • Finally, output the version number of the MySQL server.
  • Finally, close the database connection and free up the resources.

Notes:

  • mysqli::$server_version attribute is read-only and cannot be modified.
  • This function is available in PHP 5.3.0 and above.
  • The returned version number is an integer representing the internal encoding of the MySQL server version.
  • If the connection fails or is not connected to the MySQL server, the value of this property is 0.
Similar Functions
Popular Articles