- PHP 和 MySQL 教程
- PHP 和 MySQL - 主頁
- PHP 和 MySQL - 概述
- PHP 和 MySQL - 環境設定
- PHP 和 MySQL 示例
- PHP 和 MySQL - 連線資料庫
- PHP 和 MySQL - 建立資料庫
- PHP 和 MySQL - 刪除資料庫
- PHP 和 MySQL - 選擇資料庫
- PHP 和 MySQL - 建立表
- PHP 和 MySQL - 刪除表
- PHP 和 MySQL - 插入記錄
- PHP 和 MySQL - 選擇記錄
- PHP 和 MySQL - 更新記錄
- PHP 和 MySQL - 刪除記錄
- PHP 和 MySQL - Where 子句
- PHP 和 MySQL - Like 子句
- PHP 和 MySQL - 排序資料
- PHP 和 MySQL - 使用連線
- PHP 和 MySQL - 處理 NULL
- PHP 和 MySQL - 資料庫資訊
- PHP 和 MySQL 有用資源
- PHP 和 MySQL - 快速指南
- PHP 和 MySQL - 有用資源
- PHP 和 MySQL - 討論
PHP 和 MySQL - 資料庫資訊示例
MySQL 中有一些重要命令,可以在 MySQL 提示符下執行,或者使用任何指令碼(如 PHP)來獲取有關資料庫伺服器的各種重要資訊。
| 序號 | 命令和描述 |
|---|---|
| 1 |
SELECT VERSION( ) 伺服器版本字串 |
| 2 |
SELECT DATABASE( ) 當前資料庫名稱(無則為空) |
| 3 |
SELECT USER( ) 當前使用者名稱 |
| 4 |
SHOW STATUS 伺服器狀態指示器 |
| 5 |
SHOW VARIABLES 伺服器配置變數 |
示例
嘗試以下示例以獲取資料庫資訊 -
將以下示例複製並貼上為 mysql_example.php -
<html>
<head>
<title>Getting MySQL Database Info</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root@123';
$dbname = 'TUTORIALS';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
$tutorial_count = null;
if($mysqli->connect_errno ) {
printf("Connect failed: %s<br />", $mysqli->connect_error);
exit();
}
printf('Connected successfully.<br />');
if ($result = mysqli_query($mysqli, "SELECT DATABASE()")) {
$row = mysqli_fetch_row($result);
printf("Default database is %s<br />", $row[0]);
mysqli_free_result($result);
}
$mysqli->close();
?>
</body>
</html>
輸出
訪問部署在 Apache Web 伺服器上的 mysql_example.php 並驗證輸出。
Connected successfully. Default database is tutorials
廣告