You are here: Re: Designing with Databases - Best Practice Class Hierachy? « All PHP « IT news, forums, messages
Re: Designing with Databases - Best Practice Class Hierachy?

Posted by NC on 06/25/06 23:43

LiveFreeAndRoam wrote:
>
> ------------------------------------------------
> class DataAccess extends MDB2 {
> // DataAccess properties and methods
> var $db;
> function __construct($dsn) {
> $this->db =& MDB2::factory($dsn);
> }
> }
>
> class Table {
> // table properties and methods
> var $dao;
> function __construct() {
> $this->dao = new DataAccess(); // <<< OK?
> }
> }
>
> class Product extends Table {
> // Product properties and methods
> }
> --------------------------------------------------
>
> One issue I have noticed is that when I attempt to recover
> the Product Object from the $_SESSION superglobal that
> the DataAccess object is unusable. MDB2 complains with:
>
> MDB2 Error: not found: could not find MDB2 instance

Try calling parent::__construct() explicitly within
DataAccess::__construct():

class DataAccess extends MDB2 {
// DataAccess properties and methods
var $db;
function __construct($dsn) {
parent::__construct(); // Are there required parameters?
//
-------------------------------------------------------------------
// Now DataAccess has all properties and methods
// of MDB2, including the factory() method, so you
// can call the factory() method directly:
$this->db =$this->factory($dsn);
}
}

> Is there a better way to design this?

Design has to achieve certain objectives. Since you didn't state your
objectives, no one can offer you an informed guess as to what other
design would be better to achieve those objectives...

Cheers,
NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация