How to declare a variable at the bottom of the page and use its value at the top?

First, your question is purely PHP, I do not see a relationship with WordPress.
If you want to link the two variables, you must use what is called: Passing by reference

In your case :

$first = & $second

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