Why does ‘get_the_ID’ work outside of the loop?

The get_the_ID() function uses the global $post variable, which outside of the loop is sometimes equal to get_queried_object_id(). Within the loop, the $post variable is set to the current post within the loop.

As to why get_queried_object_id() is recommended outside of the loop, is because it does not use the global $post variable, so is less likely to be corrupted by loops.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)