How can error messages generated by MySQL in PHP be more specific to pinpoint the exact issue in the query?

When error messages generated by MySQL in PHP are vague, it can be challenging to pinpoint the exact issue in the query. To make error messages more specific, you can enable error reporting in PHP and utilize the mysqli_error() function to retrieve detailed error information directly from MySQL.

// Enable error reporting in PHP
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Execute the query
$result = mysqli_query($connection, $query);

// Check for errors
if (!$result) {
    die('Query error: ' . mysqli_error($connection));
}