How to check main blog in a multisite using if statement?

You can use is_main_site conditional tag like this:

if (is_main_site()) {
  execute this sql;
}
else {
  execute this sql
}

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