What is the significance of executing "SHOW STATUS" as an SQL query in PHP?
Executing "SHOW STATUS" as an SQL query in PHP allows you to retrieve various server status variables that can provide valuable information about the current state of the MySQL server. This can be useful for monitoring performance, diagnosing issues, and optimizing database operations.
<?php
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Execute SHOW STATUS query
$result = $conn->query("SHOW STATUS");
if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_assoc()) {
echo "Variable: " . $row["Variable_name"]. " = " . $row["Value"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>