What function can be used to display MySQL errors in PHP?

To display MySQL errors in PHP, you can use the mysqli_error() function. This function returns the error message from the most recent MySQL function call. By checking for errors after executing MySQL queries, you can handle them appropriately in your PHP code.

// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Execute MySQL query
$result = $mysqli->query("SELECT * FROM table");

// Check for errors
if (!$result) {
    echo "Error: " . $mysqli->error;
}

// Close connection
$mysqli->close();