mysql - PHP Class design - Get multiple objects -


i have static getuser($userid) method in user class queries database , returns user object given user id.

at times, have multiple users need obtain @ same time. i've come 2 options:

  1. create getusers() method can take multiple id's , 1 query.
  2. create getusers() method can take multiple id's uses getuser method (multiple db queries).

in both cases, returning array of user objects. should happen if userid in valid or doesn't exist? exclude user array? seems weird.

so great answers to:

  • should use option 1 or 2?
  • what should happen in event of invalid user id, ignore it? or throw exception?

feel free critique use of static method getuser() too, don't know else put method, thanks.

this don't think should optimize until becomes bottle neck.

it cleaner if split up. in fact, recommend create folder , call collections example. in there have example usercollection allows iterate on different sets of users. current() method return user object.

for getuser() part, put things user object folder called entities. objects handle crud operations of single user while collections there return sets of users (or single user).

in entity part can throw exception if not found. collection should return valid ids.

as sidenote, can mix different objects in collection when use iterators, can pretty useful in cases.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -