2024 年 PHP Conference Japan

mysqli::$server_info

mysqli::get_server_info

mysqli_get_server_info

(PHP 5, PHP 7, PHP 8)

mysqli::$server_info -- mysqli::get_server_info -- mysqli_get_server_info傳回 MySQL 伺服器版本

說明

物件導向風格

public mysqli::get_server_info(): 字串

程序式風格

mysqli_get_server_info(mysqli $mysql): 字串

傳回一個字串,表示 MySQLi 擴充套件連線的 MySQL 伺服器版本。

參數

mysql

僅限程序式風格:由 mysqli_connect()mysqli_init() 返回的 mysqli 物件

回傳值

代表伺服器版本的字串。

範例

範例 #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

另請參閱

新增註解

使用者貢獻的註解 1 則註解

it-solutions at schultz dot ch
8 年前
請注意,此屬性在 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 擴充功能的此屬性
To Top