What are some best practices for optimizing PHP MySQL queries for performance?

To optimize PHP MySQL queries for performance, it is important to use indexes on columns frequently used in WHERE, ORDER BY, and GROUP BY clauses, limit the number of columns returned in SELECT queries, avoid using SELECT *, use parameterized queries to prevent SQL injection attacks, and minimize the number of queries executed by combining multiple queries into a single query where possible.

// Example of optimizing a MySQL query by adding an index on a column
$query = "CREATE INDEX index_name ON table_name(column_name)";
$result = mysqli_query($connection, $query);
if($result) {
    echo "Index created successfully";
} else {
    echo "Error creating index: " . mysqli_error($connection);
}