Using either a SQL query, or some php code, how can I determine which version of MySQL is running. I found several examples of using the command line, but I need to check programmatically.
I tried
SELECT @version;
But that returned NULL.
I did search stack overflow, and found a lot of questions, but they were about other dbs or programming languages. I didn't find any specifically for MySQL.
CodePudding user response:
Correct syntax with mysql is select version();
CodePudding user response:
You can get by user mysqli_server_info or the oop way using $mysqli->server_info;
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* print server version */
printf("MYSQL Server version: %s\n", $mysqli->server_info);
$mysqli->close();
Or in MYSQL Query way
SELECT VERSION();
Or you may want to show in detailed way
SHOW VARIABLES LIKE "%version%";