How can I run code in functions.php when switch_theme() is called?

Well, instead of using a $_GET parameter you could store a initiate state in your options-table.

E.g.

$initialized = get_option('mytheme_initialized');
if ( (false === $initialized) && is_admin() && ($pagenow == 'themes.php') ) {
//this code only runs when the theme is first activated
update_option('mytheme_initialized', true);
}

Unfortunately the “register_activation”-hook is only available for plugins -> http://core.trac.wordpress.org/ticket/13602

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