I can't tell you if there is a library for distributed transactions in PHP/MYSQL. I think you have to write something like that yourself.
I don't know what you want to achieve with your code but it's basically nothing more than double-checking the synchronized databases on two servers. And that can be done with mysql_connect().
What I want is like this first I have local of a db.Then one submit of the form just say I will need to insert and update in another of this local db in the cental server. At the same time in the central server I also have a central db which I will do mostly update statement only. So I hope I am clearer now?