How can MySQL system data such as QueryTime or DB load be displayed using PHP?
To display MySQL system data such as QueryTime or DB load using PHP, you can use MySQL queries to fetch this information from the database and then display it on a webpage. You can use functions like mysqli_query() to execute queries and retrieve the data. Once you have fetched the data, you can format it and display it using PHP echo statements.
<?php
// Connect to MySQL database
$connection = mysqli_connect("localhost", "username", "password", "database");
// Check connection
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
// Query to fetch QueryTime and DB load
$query = "SHOW GLOBAL STATUS LIKE 'Questions'";
$result = mysqli_query($connection, $query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "QueryTime: " . $row["Variable_name"] . " - " . $row["Value"] . "<br>";
}
} else {
echo "No data found";
}
// Close connection
mysqli_close($connection);
?>
Keywords
Related Questions
- In the provided PHP code for a form submission, what are some best practices for sanitizing user input to prevent security vulnerabilities or errors in the application?
- Are there best practices for filtering and searching for special characters in user input in PHP?
- What are the advantages of using DateTime over strtotime for date and time manipulation in PHP?