I have been playing about with an Ajax/PHP site and I am wondering about the best practices concerning calls to multiple PHP files Vs a single PHP file with many functions in it.
All of these calls are simple database access calls - returning data from a query. It seems a sensible thing to have a single file that opens the database and contains multiple functions, one for each of the calls, however I do not know the best practices in this instance and I am unaware of any security concerns that there may be.
Does anyone know the best practice in this case?
Cheers
BK
It's a matter of opinion, really. If you haven't got much code, and don't intend to re-use any of it elsewhere, you may as well just have it all in one file. You don't want to fall into the trap of over-complicating what might be a simple setup.
If your code starts to build up and become difficult to follow, you will then be better off splitting it across a number of files based on the sort of task they perform. This is the concept frameworks are based on, where maintaining a more complex application structure is more beneficial to your productivity than fumbling with a monolithic index.php.
And finally: it is vital to take these considerations into account when expecting other people to work with your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With