The mysqli_connect_errno() function returns the error code from the last connection error, if any.
mysqli_connect_errno();