Re: PHP - class question

From: Date: Wed, 14 Aug 2002 19:17:00 +0000
Subject: Re: PHP - class question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-112585@lists.php.net to get a copy of this message
Well, I actually have a full db class which has a connect and close method as well as query, fetch_array, etc... What I really want to know is how to use the methods in my db class from another class (myclass for example).. Do I include the db class from the myclass constructor and then set a myclass variable = to the db object? ie. class my_class { var $db; function my_class() { include('class_database.php'); $this->db = new database; } ... } or is there a differnet or better way? Thanks Mark "Steve Bradwell" <SteveB@compxnet.com> wrote in message news:57A1618E7109D311A97D0008C7EBB3A10119EF03@KITCHENER... > I would suggest you write a method (called mydb() for example) that connects > to your database, and if needed, call it from your constructor like: > $this->mydb(); This way you can always reuse the method from other code. > > hth, > Steve. > > -----Original Message----- > From: Mark Armendariz [mailto:PHP@enobrev.com] > Sent: Wednesday, August 14, 2002 2:44 PM > To: php-general@lists.php.net > Subject: [PHP] PHP - class question > > > Hello, To begin.. i'm new to the list... > > I'm trying to learn good practices in OOP based PHP. I'm actually a bit new > to OOP in general, but I've done quite a bit of reading and playing around > with it in the past couple of months. > > What I'm trying to figure out is the proper way to call a class from a > class. I dont mean by extending the class, but actaully just getting the > functions... > > For instance... > > I'm trying to connect to a Database (database class) from my gen_XML class. > Do I include the database class in the gen_XML constructor? Do I set a > gen_XML variable as a database object (i.e. $this->mydb)? > > I hope my question makes some sense... > > Your help is appreciated... > > Mark Armendariz > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#112585) next »