papacostas Posted June 23, 2006 Share Posted June 23, 2006 im trying to plan and write a flexible and simple DAO for all my SQL.I want to be able have a class that decides what function to use based on how many objects im throwing at it.I recall writing classes like this in Java but i cant be able to make it work in PHPfor instance function sql($variable) { generate sql + db fetch code }function sql($variable, $variable) { generate sql based on two variables + db fetch code }what i mean is the same function name but different amount of variables, im sure you get what im trying to do.i've made similar classes in the past but i always end up having a crapload of functions based on how many variables i need, does anyone have any thoughts about how to go about with this problem?I've read numerous of how to create DAO articles but I find them all overly complicated and not reallydealing with what i need.how did set up your DAO class structure?any general thoughts on the subject? Quote Link to comment https://forums.phpfreaks.com/topic/12749-php-data-acess-object-class/ Share on other sites More sharing options...
Eric_Ryk Posted June 23, 2006 Share Posted June 23, 2006 [!--quoteo(post=387259:date=Jun 23 2006, 01:57 PM:name=papacostas)--][div class=\'quotetop\']QUOTE(papacostas @ Jun 23 2006, 01:57 PM) [snapback]387259[/snapback][/div][div class=\'quotemain\'][!--quotec--]im trying to plan and write a flexible and simple DAO for all my SQL.I want to be able have a class that decides what function to use based on how many objects im throwing at it.I recall writing classes like this in Java but i cant be able to make it work in PHPfor instance function sql($variable) { generate sql + db fetch code }function sql($variable, $variable) { generate sql based on two variables + db fetch code }what i mean is the same function name but different amount of variables, im sure you get what im trying to do.i've made similar classes in the past but i always end up having a crapload of functions based on how many variables i need, does anyone have any thoughts about how to go about with this problem?I've read numerous of how to create DAO articles but I find them all overly complicated and not reallydealing with what i need.how did set up your DAO class structure?any general thoughts on the subject?[/quote]Well you could do something like this:[code]function sql(){ $args = func_num_args; switch($args) { // cases and calls to other functions here // ex: case 1: sql1(func_get_args()); break; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12749-php-data-acess-object-class/#findComment-48906 Share on other sites More sharing options...
.josh Posted June 24, 2006 Share Posted June 24, 2006 hi. I just recently decided to start learning php OOP, so I can't tell you for sure, but i thought i read that php oop does not support polymorphism?i suppose you could do a workaround, like, if you knew you were gonna pass at most 3 arguments, go ahead and pass empty vars for the ones you don't need, and do a check to see if vars are empty, and base your code off of empty vars. Quote Link to comment https://forums.phpfreaks.com/topic/12749-php-data-acess-object-class/#findComment-49011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.