How can PHP, JavaScript, and AJAX be effectively integrated in a website structure?

To effectively integrate PHP, JavaScript, and AJAX in a website structure, you can use PHP to handle server-side processes and data manipulation, JavaScript for client-side interactivity and user interface enhancements, and AJAX for asynchronous communication between the client and server without reloading the entire page.

<?php
// PHP code to fetch data from database
$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);

// Output data of each row
while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["name"]. " - Email: " . $row["email"]. "<br>";
}

$conn->close();
?>