I am experimenting on a sort-of MVC structure PHP project.
Suppose I have a model for users, that looks like this: (I am using pseudocode)
function addUser($name, $surname) {
mysql_query("insert into users name=$name surname=$surname");
return true;
}
function getUser($id) {
$object = mysql_query("select from users where id=$id limit 1");
return $object;
}
and in my controller I have:
$user = getUser("foo");
so I can access user information to be printed out easily like this:
$name = $user["name"];
so far, so easy. The problem which I suppose I might face if I keep going this way is that, if one day I will have to change the column 'name' into say, just 'n', all the components that are getting the object returned by getUser() will have to be modified to reflect that change.
How does it work in this cases to avoid such problem?
P.S. I know this is not exactly MVC but a VMC-ish structure; it's just to get the idea on how to do it. If I made any mistake explaining please be patient and don't freak out: we are humans and not robots and most importantly we are here to LEARN.
why I said that is that I am actually not using mysql but mongodb, which as the object structure like this: {name:"foo", surname:"fuu"} that is basically repeated for every object so I thought that to save space in the db I might just decide to change it one day from 'name' to just 'n', saving 3 ascii chars per object! It's out of the scope of the question but I think you understand now why I need to use this.