What best practices should be followed when writing SQL queries in PHP to avoid ambiguity in column names?

When writing SQL queries in PHP, it is important to avoid ambiguity in column names by using table aliases to clearly identify which table a column belongs to. This helps prevent errors and confusion, especially when joining multiple tables in a query. Additionally, using backticks around column and table names can also help avoid naming conflicts with reserved keywords in SQL.

$query = "SELECT t1.column1, t2.column2
          FROM table1 t1
          JOIN table2 t2 ON t1.id = t2.id";
$result = $conn->query($query);