Do not run this code on posts with a specific tag!

This is more of basic PHP. You are correct in choice of function, you merely need to reverse the condition with logical Not operator:

if( !has_tag('test') ) {

}

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