Get post id outside loop : Notice: Trying to get property of non-object

You can not get post ID in init hook. The first safe hook to get post id is template_redirect.

See this answer for more details:

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