2024.8.23
Loading...
Searching...
No Matches
ajax.mysql.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
11
12/**
13 * This script checks the status of the MySQL service and retrieves its versions.
14 * It creates an array with keys 'checkport' and 'versions', which are populated with HTML strings
15 * indicating the status of the MySQL service and its available versions, respectively.
16 * The final result is encoded in JSON format and echoed out.
17 */
18
19// Initialize result array
20$result = array(
21 'checkport' => '',
22 'versions' => '',
23);
24
25// Check port
26$port = $bearsamppBins->getMysql()->getPort();
27
31
32/**
33 * Check if MySQL service is enabled and its port status.
34 * If enabled, check if the port is open and set the appropriate status message.
35 * If disabled, set the status message to indicate that the service is disabled.
36 */
37if ($bearsamppBins->getMysql()->isEnable()) {
38 if ($bearsamppBins->getMysql()->checkPort($port)) {
39 $result['checkport'] .= '<span class="float-end badge text-bg-success">' . sprintf($textServiceStarted, $port) . '</span>';
40 } else {
41 $result['checkport'] .= '<span class="float-end badge text-bg-danger">' . $textServiceStopped . '</span>';
42 }
43} else {
44 $result['checkport'] = '<span class="float-end badge text-bg-secondary">' . $textDisabled . '</span>';
45}
46
47/**
48 * Retrieve the list of MySQL versions and highlight the current version.
49 * Add each version to the 'versions' key in the result array, using different badge styles
50 * to indicate the current version and other versions.
51 */
52foreach ($bearsamppBins->getMysql()->getVersionList() as $version) {
53 if ($version != $bearsamppBins->getMysql()->getVersion()) {
54 $result['versions'] .= '<span class="m-1 badge text-bg-secondary">' . $version . '</span>';
55 } else {
56 $result['versions'] .= '<span class="m-1 badge text-bg-primary">' . $bearsamppBins->getMysql()->getVersion() . '</span>';
57 }
58}
59
60// Output the result as a JSON-encoded string
61echo json_encode($result);
$result
$textServiceStopped
$textDisabled
global $bearsamppBins
global $bearsamppLang
$port
$textServiceStarted
const HOMEPAGE_SERVICE_STOPPED
const HOMEPAGE_SERVICE_STARTED
const DISABLED