Wade, You dont have to change the database table. For example:
If you have a users table but you dont have the 'country' field you only have to do this: $user = new DatabaseObject_User(); $user->load(1234); //the user id that you want $user->profile->country = 'brazil ; $user->save(); This will add another row on 'users_profile' table: - user_id = 1234 - profile_key = 'country' - profile_value = 'brazil' Your 'users' table is the same, you only have added a new column on 'users_profile' table with a link to your user. So if you want get the user's country: $user = new DatabaseObject_User(); $user->load(1234); echo $user->profile->country; This will automatically do a select into users and users_profile (join) tables and group into the $user object; Ok? Junior Grossi [EMAIL PROTECTED] On Sun, Oct 12, 2008 at 4:09 PM, Wade Smart <[EMAIL PROTECTED]> wrote: > Junior Grossi wrote: >> Hi all, >> >> I've read the book 'Practical Web 2.0 Applications with PHP' and in >> that book the author uses a different database modeling. >> I'll give you an example, if you have a 'users' table with a lot of >> columns like, first name, last name, country, food, etc... He suggests >> that you create 2 tables, called 'users' and 'users_profile": >> >> - users table: >> user_id >> username >> password >> ... >> >> - users_profile >> user_id >> profile_key >> profile_value >> >> So... if you have to insert the user's country, you insert into >> users_profile table: (7162, 'country', 'brazil')... >> >> So, the author give us two classes to manipulate the user object and >> profile (DatabaseObject and Profile classes). >> If you want to get the user's country you use: >> >> $user = new DatabaseObject_User(); >> $user->load(7162); //the user id >> echo $user->profile->country; //will print 'brazil' >> >> It's good because you can insert a lot of information without change >> the database table.. only adding a new property in the user class. >> >> What do you think about this new modeling? Have you used this? >> Detail: if you have to sum double numbers, for example, the mysql did >> the sum normally. >> >> Thanks. >> >> Junior Grossi >> [EMAIL PROTECTED] > > 20081012 1306 GMT-6 > > I have something similar lately and it too relied heavily on objects > (which I have to admit I have not really got into - though I should) and > it looked like it would definitely help out in certain situations. > > But Im not sure I understand what you said about not changing anything > to the db table. > > If you didnt already have a field for country and then wanted to add it > later, as I read what you just wrote you would changed the db at all - > but that cant be can it since you have to have a place to put that value? > > Wade >