Editor 1.3.1 connect to Multiple Databases

Editor 1.3.1 connect to Multiple Databases

bmx123bmx123 Posts: 13Questions: 4Answers: 1

I am trying the new version of Editor. Is it possible to have have connections to multiple databases, all on the same server, and all with the same username/password? The config.php file allows for only one connection.

With reference to the discussion here, you said to add a new database like this:

$data = Editor::inst( $db, 'dt.releases' )

Following this, if I understand correctly, in the config.php file I have a connection to Datatbase1. In my php server-side script, taken from one of the Examples, I have a connection to a table in Datatbase1, as follows:

Editor::inst( $db, 'Table1' )

For another table, if I want to use a different database, ie Database2, where do I call the table for Database2? I tried this, but it did not work

Editor::inst( $db, 'dt.Database2', 'Table22' )

many thanks,

Ken

Replies

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    The config.php file allows for only one connection.

    The config.php file does yes, but you can create as many instances of the database class as you wish, using the same method as the config.php file. You would just assign the second database to another variable - $db2 or whatever!

    However, if your login user for the database has access privileges for both databases, you can indeed just use a database qualifier as you suggest. I do that myself for joining two tables which are in two different MySQL databases, but which the user has access to read.

    In the example you give, for SQL the left hand side is more specific, so it goes database.table.field (which parts left out as needed). So you might have:

    Editor::inst( $db, 'Database2.Table22' )
    

    which will access Table22 in the Database2 schema.

    Allan

  • bmx123bmx123 Posts: 13Questions: 4Answers: 1

    Perfect. Thanks.

This discussion has been closed.