php mysql database distribute middleware