Jump to content

PHP Data Acess Object Class


papacostas

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/12749-php-data-acess-object-class/
Share on other sites

[!--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 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:
[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]
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.