How can reserved words in MySQL affect PHP queries?

Reserved words in MySQL can cause syntax errors when used in PHP queries. To avoid this issue, you can enclose reserved words in backticks (`) in your SQL queries. This will ensure that the reserved words are treated as identifiers rather than keywords by MySQL.

<?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);
}

// Using backticks to handle reserved words in MySQL
$sql = "SELECT `column`, `table` FROM `my_table`";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "Column: " . $row["column"]. " - Table: " . $row["table"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>