Jump to content


Photo

PHP Data Acess Object Class


  • Please log in to reply
2 replies to this topic

#1 papacostas

papacostas
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 June 2006 - 05:57 PM

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 PHP


for 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 really
dealing with what i need.

how did set up your DAO class structure?
any general thoughts on the subject?


#2 Eric_Ryk

Eric_Ryk
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 23 June 2006 - 08:24 PM

[!--quoteo(post=387259:date=Jun 23 2006, 01:57 PM:name=papacostas)--][div class=\'quotetop\']QUOTE(papacostas @ Jun 23 2006, 01:57 PM) View Post[/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 PHP
for 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 really
dealing 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:
function sql()
{
   $args = func_num_args;
   switch($args)
   {
       // cases and calls to other functions here
       // ex:
       case 1:
          sql1(func_get_args());
          break;
   }
}


#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 June 2006 - 06:57 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users