|
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]
|