WordPress loop put title into variable

Creating variables on the fly like that is not needed. Just use an array instead.

$myvars = [];

inside your foreach loop you can:

$myvars[] = array('title'=>$t,'image'=>$v);

After your loop you can:

//First title, First image
echo $myvars[0]['title'];
echo $myvars[0]['image'];

//Second title, Second image
echo $myvars[1]['title'];
echo $myvars[1]['image'];

This way you can always print_r($myvars) and see the content inside of it.

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