How can the mysql_error() function be used to troubleshoot SQL query errors in PHP?

To troubleshoot SQL query errors in PHP, you can use the mysql_error() function to display the error message generated by the most recent MySQL operation. This can help identify the cause of the error and make necessary adjustments to the SQL query.

$query = "SELECT * FROM users WHERE id = '123'";
$result = mysql_query($query);

if (!$result) {
    die('Error: ' . mysql_error());
}

// Continue processing the query result