On 8 Dec 2011, at 17:14, Dominik Halvoník wrote:

> I would like to ask you for help. This days I am trying to build one of my
> applications. But I have problem which stopped me. I have folder whit php
> files like connect.php, delete.php etc. These files contains classes named
> the same as files. So in file connect.php is class Connect. These files are
> placed in folder named mysql and this folder is inside folder named db. In
> folder db is a php file named mysql.php, in this file I include classes
> from folder mysql, after include I declare class MySQL and in it I have
> method __construct(). In this method I create dynamic objects from included
> classes. And this is the problem that I can not solve, I have more then one
> of this files(mysql.php[whit class MySQL], oracle.php[whit class Oracle]
> etc.) and I need to include them to file called db.php that is in the main
> folder of my app. In db.php is an class called db, how can I add classes
> MySQL, Oracle etc. to class db? I try to use abstract class whit __set and
> __get methods but I also need to include class db to main class
> application. I am really sorry for my English, so please be indulgent. So I
> need to connect classes like this:
> application->db->mysql->connect, but I can not use extends because in php
> you can have only one parent class. The reason why I am trying to do
> something like this is because I want to call methods like this:
> $test = new application();
> $test->db->connect();
> If it is mysql or othet database I set in config.php file. Can you help my
> please?

You don't say what the db class (in db.php) itself does other than wrapping the 
database-specific classes, so I've assumed it doesn't do anything. If it does 
do more then simply have the mysql, oracle, etc classes extend db.

I've also assumed that the application doesn't need to support multiple 
database types simultaneously.

class application
  public $db = null;

  function __construct($db = 'mysql')
    require __DIR__.'/db/'.$db.'.php';
    $this->db = new MySQL();

$test = new application('mysql');


Stuart Dallas
3ft9 Ltd

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

Reply via email to