What are the advantages and disadvantages of using PHP for dynamic menu navigation and database querying in a website?

Issue: When creating a dynamic menu navigation and querying a database in a website, using PHP can be advantageous due to its flexibility, ease of use, and compatibility with various database systems. However, PHP can also be prone to security vulnerabilities if not properly sanitized and validated.

<?php
// Connect to 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);
}

// Query database for menu items
$sql = "SELECT * FROM menu_items";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<a href='" . $row["url"] . "'>" . $row["title"] . "</a>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>