SEF add_rewrite_rule & add_rewrite_tag not working

Looks like the problem is flushing rules. Flushing rules from Settings-Permalinks doesn’t help somehow, so I did it in code like this:

if (! in_array('index.php?pagename=$matches[1]&dir=$matches[2]', get_option('rewrite_rules'))) {
    flush_rewrite_rules();
}

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