What are the potential benefits of logging database queries in PHP scripts?

Logging database queries in PHP scripts can provide valuable insights into the performance of your database operations, help in debugging and troubleshooting issues, and track the execution flow of your application. By logging queries, you can analyze the frequency of certain queries, identify slow-performing queries, and optimize your database interactions for better efficiency.

// Enable query logging in PHP
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', '/path/to/logfile.log');

// Log database queries
function logQuery($query) {
    error_log("Database query: " . $query);
}

// Example usage
$query = "SELECT * FROM users WHERE id = 1";
logQuery($query);