How does server-side execution of PHP code differ from client-side events in terms of functionality?

Server-side execution of PHP code allows for dynamic content generation and database interaction on the server before the page is sent to the client. This means that PHP code is processed on the server, and the resulting HTML is sent to the client's browser. On the other hand, client-side events in JavaScript are triggered and executed on the client's browser, allowing for dynamic changes to the page without needing to reload the entire page.

<?php
// Server-side PHP code to fetch data from a database and display it on a webpage
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, name, email FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["name"]. " - Email: " . $row["email"]. "<br>";
  }
} else {
  echo "0 results";
}
$conn->close();
?>