You are here: Re: Objects saving and restoring with MySQL « PHP Programming Language « IT news, forums, messages
Re: Objects saving and restoring with MySQL

Posted by Peter Fox on 01/12/06 11:05

Following on from David Wahler's message. . .
>NC wrote:
>> Gav wrote:
>> >
>> > If you had a class user with variables id, name, password. How
>> > would you save this object or its variable date to a MySQL
>> > database?
>>
>> By using serialize($your_object) and writing the result into a TEXT or
>> VARCHAR field.
>
>I don't see how that's better than having separate database fields for
>each object member. It makes it very difficult to efficiently query the
>database based on different criteria, or to migrate to any language
>besides PHP.
>
>-- David
>
What you do is set up a table with fields something like
uID,uStatus,uName,uData
where data is blob/text.

You can select on some items of data but you have complete flexibility
in the blob when you serialise the object. Suppose for example the user
object contains a variable size array. Mapping that to table fields
would be a pain or setting up another table for 1 user to many array
elements complete overkill when the information isn't going to be used
in any other context. For example an array of passwords used in last
three months by this user to prevent immediate re-use.[1]



[1] Don't try this at home kids! Never store passwords.
--
PETER FOX Not the same since the porcelain business went down the pan
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация