I have few doubts:
1.Why you can given different database names like (db1,db2,db3).My database name should be a_$site1_current.Only the $site1 should be changed as per hash.
2,In the above code i had not fount any words which matches as like a_site1_current.