請注意,此屬性在 Linux 和 Windows 環境中的 MariaDB 執行個體會返回不同的版本字串。
對於 MariaDB 10.0.17 執行個體
在 Linux 上,會返回類似「10.0.17-MariaDB-log」的字串
在 Windows 環境中,會返回類似「5.5.5-10.0.17-MariaDB-log」的字串
為了避免在 Windows 環境中出現額外的「5.5.5」,您可以使用 SQL 查詢「select version();」而不是 mysqli 擴充功能的此屬性
(PHP 5, PHP 7, PHP 8)
mysqli::$server_info -- mysqli::get_server_info -- mysqli_get_server_info — 傳回 MySQL 伺服器版本
物件導向風格
程序式風格
傳回一個字串,表示 MySQLi 擴充套件連線的 MySQL 伺服器版本。
代表伺服器版本的字串。
範例 #1 $mysqli->server_info 範例
物件導向風格
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password");
/* 顯示伺服器版本 */
printf("伺服器版本:%s\n", $mysqli->server_info);
程序式風格
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password");
/* 顯示伺服器版本 */
printf("伺服器版本:%s\n", mysqli_get_server_info($link));
上述範例會輸出類似以下的內容:
Server version: 8.0.21
請注意,此屬性在 Linux 和 Windows 環境中的 MariaDB 執行個體會返回不同的版本字串。
對於 MariaDB 10.0.17 執行個體
在 Linux 上,會返回類似「10.0.17-MariaDB-log」的字串
在 Windows 環境中,會返回類似「5.5.5-10.0.17-MariaDB-log」的字串
為了避免在 Windows 環境中出現額外的「5.5.5」,您可以使用 SQL 查詢「select version();」而不是 mysqli 擴充功能的此屬性