Re: [PHP-PEAR] Addition to DB/common.php ?

[email protected] (Kendrick Vargas)
Newsgroups php.pear
Message-ID <[email protected]>
On Fri, 2 Feb 2001, Kendrick Vargas wrote:

> I call it my Data_Container. I usually extend it like so:
>
> class Domain_Info extends Data_Container {
>
>    var $table_name = "dns_zones";
>    var $id_name = "zone_id";
>    var $db = "";
>
>    function Domain_Info ($id = "") {
>       $this->db = new DB_Connection("temp_auth");
>
>       if ( $this->Container_Init($id) ) {
>          return(true);
>       } else {
>          return(false);
>       }
>
>    }
>
> }

I suppose I should also give some usage examples :-)

Usually, when I've extended a class as I have above, I will do the
following:

$zone = new Domain_Info();
$zone->set_fields($values);   // Where $values is an array index on
                              // field names
$zone->commit_changes();      // and commit my changes.

That's for the case of a new entry. In the case of an existing entry, I'd
just start with:

$zone = new Domain_Info($domain_id);

where $domain_id is the id in the database for the entry. Everything else
would be the same.

I suppose that an interesting way to abstract it further would be to
create seperate "storage" routines. I.e.. Have the functions that just set
the fields and what not be in one class, and then have the functions that
actually interact with the databases be seperate files. That way it could
have storage drivers for mysql, postgres, maybe text files, etc... That
would partially solve my problem of requiring mysql (I use the
LAST_INSERT_ID() function in mysql to get back the last auto_increment
assigned).
			-peace

--- BEGIN GEEK CODE BLOCK ----------+----------
GAT d- s:+ !a C++$ UL/S/I/B++++$ P+ | "In the ongoing battle between objects
L++ E- W+(+++) N K-  w(---)  O-- M@ |  made of aluminum  going hundreds of
V(--) PS+++  PE Y+ PGP@ t++ 5 X+ R- |  miles per hour and the ground going
tv+ b- DI++++  D+(+++) G  e>++ h--- |  zero,  the  ground has yet  to lose."
r++ z+>+++ - END GEEK CODE BLOCK ---+
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.