How can the mysql_query() function in PHP be used to check if a database operation was successful?

To check if a database operation was successful using the mysql_query() function in PHP, you can use the mysql_affected_rows() function to determine the number of affected rows after the query execution. If the number of affected rows is greater than zero, then the operation was successful.

$query = "INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2')";
$result = mysql_query($query);

if(mysql_affected_rows() > 0) {
    echo "Database operation was successful.";
} else {
    echo "Database operation failed.";
}