Get the post id as early as possible

The earliest action you can use is ‘wp’. You can read more about it here: Action WP.

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