Thursday, August 15, 2002, 5:17:00 AM, you wrote:
MA> Well, I actually have a full db class which has a connect  and close method
MA> as well as query, fetch_array, etc... What I really want to know is how to
MA> use the methods in my db class from another class (myclass for example)..

MA> Do I include the db class from the myclass constructor and then set a
MA> myclass variable = to the db object?

MA> ie.

MA> class my_class {
MA>     var $db;

MA>     function my_class() {
MA>         include('class_database.php');

MA>         $this->db = new database;
MA>     }

MA>     ...
MA> }

MA> or is there a differnet or better way?

I set up interclass communication by having a global array for
references like this:
class a {
      var $t = 'Empty';
      function a(){
               global $classes;
               $classes['a'] =& $this;
      function test(){
               echo $this->t;

class b {
      var $a; //class a holder
      function b(){
               global $classes;
               //if the class already exists use it...
                      $this->a =& $classes['a'];
               //otherwise create it...
                      $this->a = new a();
$a1 =& new a();
$a1->t = 'This is a test';
$b1 = new b();
whether it is better depends on usage, but it should be good for a db
class so you only make the one connection :)


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to