The mysqli_errno() function returns the last error code for the most recent function call, if any.
mysqli_errno(connection);