I have a typical website setup where I'm using AJAX to communicate with PHP scripts which are then reading and writing data to a MySQL database. In my previous projects, the amount PHP scripts I needed to make were small since there weren't many variations in the data that I needed to read or write. This site is a bit different, and my normal approach of creating a different PHP script for each AJAX call has resulted in a large amount of PHP scripts.
I decided to take a different approach and group similar queries in the same PHP script. For example, if I have the following calls:
getGroupById
getAllGroups
createNewGroup
In my previous approach, I would have three separate php files, but now I have one that does all three of these.
The second approach I have taken is proving to be unmaintainable as the project is grows. For example, if I want to have multiple GET calls in the same script, I'd have to now pass in another parameter to the script from the AJAX call so that the PHP script knows which query to perform.
Which of these two approaches would be better? Are there any well known practices or design patterns for handling this?