Re: learning classes - need pointer
| From: | Alex Hogan | Date: | Mon, 16 May 2005 20:57:08 +0000 |
| Subject: | Re: learning classes - need pointer | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-215324@lists.php.net to get a copy of this message | ||
>
> In my current case, I am trying to create all the generic SQL
> functions (IE insert, update, delete, etc). Now what I am wondering -
> what would be the best way to structure the code so that I can
> accommodate the possibilities for different fields and databases,
> etc? Is it something that I should just pass to the class? Or would
> there be a more efficient way to do it?
One of the things I hate most is having to rewrite code for insert and
update. With that in mind what I do is name the form objects the same name
as the db fields that they relate to. Then I iterate through the $_POST
array as a whole and do the insertions and updates like that. The only thing
that I have to pass to my class is the table name and any location string
that will accompany the successful completion of the insert/update. All my
validation is done right there with method overloading.
It's not extremely clever by any means but it gets the job done. Besides
I'm kinda lazy.
I'm sure there are several wrappers that do the same thing.
alex hogan