Elegant way to switch database

Elegant way to switch database

rheinertprheinertp Posts: 23Questions: 4Answers: 0

Hi,
I am using Editor with PHP and now want to be able to dynamically change the database name
(all other connection information remain the same) after a login of the user.

I read that this is possible, i.e. by
Editor::inst( $this->editorDb, 'database.table', 'idfield' ) ->field( Field::inst( 'database.table.idfield' ),

but as I already have a large amount of such definitions I would like to use change once, i.e.

$this->editorDb->setDatabase('other_database');

Is this possible? Or do I really need to add the database to every single field in the code?

Thanks,
Pascal

Replies

  • allanallan Posts: 61,732Questions: 1Answers: 10,110 Site admin

    Or do I really need to add the database to every single field in the code?

    Yes - if there are potential conflicts in name, you'd need to prefix the db name (if you are accessing multiple db's from the same instance) to each field.

    Allan

This discussion has been closed.