Create and change a database on run-time

Recently I decided to start a project and it is for some organizations. As u know different organizations have got different personal chart trees with different levels for example one of them has got 4 level when the other has got 4.

So I need a separated table for each nodes. level 1 = 1 node = 1 table and level 2 = 2 nodes and 2 tables etc

How can I create a database to cover all my chart tree shapes and how can I manage my models in Yii? can I create or manage them on run-time?

I am really confused that if I can manage these tables dynamically?

you could mix this extension I made a while ago


with something like

when needed, create the connection component










and then in your models use the extension

function connectionId(){


        return 'dynamicDb';


    	return 'db';


Thx a lot I think that’s the clue

I’m trying to do this but I’m not sure where to place the code to create a new connection component. Any guidance would be very helpful.


Hi gentlemen,

I am trying to make an application which has a list of clients in the main db. I want to create and assign a separate db to each client upon successful registration and login, so each of them can have their own set of data and processes running. Could you please let me know how will I be able to achieve this in Yii Framework.

I need the main db to login the clients and after that the tables and data should point to their personal db. When the client logs out, then it must be from the main db.

Your help is much appreciated.