I’ve been thinking about this issue for some time now and haven’t been able to conceptualize the best way to do this, despite many thinking and many attempts. I need to know what is the best way to use data flow in an interactive web application in terms of database, server-side code, and client-side code. The languages I'm working with right now are MySQL for the database, PHP for the server language, and JavaScript / CSS / HTML / jQuery for client code. I am trying to find a smart way to allow the user to safely do things like select, update, delete and insert from the database, as well as display in a nice format on the web page.
I am already very good at interesting interactive websites, writing awesome PHP applications and customizing organized and efficient database schemas. However, I struggled to find an abstract and effective methodology that brings them all together. I do not want to use the existing infrastructure. This is simply not an option for me. I am the type of person who needs to understand how everything works and what they do. However, I would look at the existing structure of pointers, but all of them that I am looking at now are basically just embarrassing me.
Here are some things to consider in my structure:
PHP code returns data from the MySQL server and back to the client side in JSON format. For example, a database query for Martin Scorsese films might return something like:
{ totalRecords: 2, records: [{ title: 'The Departed', year: '2006' }, { title: 'Goodfellas', year: '1990' }] }
The client side receives and analyzes this.
For invalid database calls, such as an invalid login, it would be better to return a valid HTTP response with a “false” (thus causing a success callback) or return an invalid HTTP error message (thus causing a failure callback).
I am not sure how to configure PHP. Should I do one function for each type of mysql operation (for example, "SELECT", "UPDATE", "DELETE" and "INSERT")? Should it be a library of functions or all contained in the class? For some reason, should there be several classes or some kind of hierarchy of classes? What are some good data access methods?
I use the jQuery ajax function to make client-side calls to the server-side, to get a JSON string and then parse it. The success callback function is called on a successful call that receives a string in JSON format. From here I hardly know what to do. I was thinking of sending the returned JSON string to some function that would parse the JSON and return something like an HTML table to display the results. However, I would not be sure how to set up the class hierarchy.
My boss at work told me about a hierarchy that looks something like this:

However, I'm not quite sure why so many parts are needed, for example, Data-Connector, Adapter, Manager / Provider, Controller and View. I am sure that I will need some of them, but not all, and I am also not sure that the best way is to create a class structure. Note that I'm somewhat new to the MVC approach.
The code should be as abstract and reusable as possible! I currently have a ton of spaghetti code, and it makes me cry inside: '- (
So ... this is where I am now. Any help would be greatly appreciated as I feel that I am a lost puppy not receiving it and that any code that I write quickly becomes sloppy and unusable or maintained. If you could give an idea of your own structure that you are using, or spend time reading my long message and evaluating my own, any contribution to make me think about it differently would be greatly appreciated. :-)