A hook that runs only when the theme is previewed

I think you could use the ?preview=true in the url something like :

if ($GET['preview']) {
// your hook or function
}

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