How can query optimization in PHP scripts help improve performance and prevent errors like "Fatal error: Maximum execution time"?
Query optimization in PHP scripts can help improve performance and prevent errors like "Fatal error: Maximum execution time" by ensuring that database queries are efficient and do not take too long to execute. This can be achieved by using indexes, limiting the number of rows returned, and avoiding unnecessary joins or subqueries.
// Example of optimizing a query using indexes
$query = "SELECT * FROM users WHERE age > 18";
// Add an index on the 'age' column in the 'users' table
// ALTER TABLE users ADD INDEX age_index (age);