Connect to external database

How to develop custom Contao extensions

Re: Connect to external database

Postby ga.n » Wed Mar 10, 2010 10:57 am

freeyland wrote:This is the code I created.
It is working fine but I get the following error message:
Runtime notice: Declaration of Database_custom::getInstance() should be compatible with that of Database::getInstance() in /var/www/html/infobase/system/drivers/DB_Oracle_custom.php on line 42
I get this error by calling:
$db2 = Database_custom::getInstance($GLOBALS['TL_CONFIG']['dbUser_Infobase'],$GLOBALS['TL_CONFIG']['dbPass_Infobase'], $GLOBALS['TL_CONFIG']['dbSid_Infobase']);

you have to put the credentials *inside* the getInstance method and not as arguments
Did you find this post useful?
You may wish to take a look at
User avatar
ga.n
User
 
Posts: 147
Joined: Fri Jun 19, 2009 5:03 pm

Re: Connect to external database

Postby freeyland » Wed Mar 10, 2010 11:06 am

OK, but how do I then connect to 2 different databases?

thx for quick reply
freeyland
User
 
Posts: 49
Joined: Mon Jun 22, 2009 6:44 pm

Re: Connect to external database

Postby ga.n » Wed Mar 10, 2010 11:17 am

freeyland wrote:OK, but how do I then connect to 2 different databases?

thx for quick reply

I think there is no "clean" solution

just get your instance and then use the setDatabase function

http://dev.typolight.org/projects/typol ... tabase.php

probably you'll need to implement the set_database function in order to reflect this change (e.g. reconnecting or something similar)
Did you find this post useful?
You may wish to take a look at
User avatar
ga.n
User
 
Posts: 147
Joined: Fri Jun 19, 2009 5:03 pm

Re: Connect to external database

Postby spartanin » Sun Jun 13, 2010 9:00 pm

Hello
I have a question concerning the above subject. How would you can connect to the second base - for example: if the table tl_comments comments module would in another database? The question relates to the amount of cooperation Contao with distributed databases.
spartanin
User
 
Posts: 9
Joined: Mon Jun 29, 2009 6:50 pm

Re: Connect to external database

Postby acenes » Mon Jun 14, 2010 7:31 am

Contao has no explicit implementation of distributed data, because such things can and should be implemented in the database layer and should be transparent to the application. Here are some pointers to different solutions, where what you describe is the second option:

  1. Load Balancing / Clustering
  2. Federated Tables

Depending on the path you take, the tables created by the Contao installer need to be modified. Also, the built in database administration is only designed for MySQL, using any other database means you need to create the tables manually anyway.
Extensions: avatar, cron, dlstats, editarea, geshi, helpdesk, recall, rep_*, smhcheck.
FAQ's - Documents - Tickets
Please no help requests by PM, use the forum or ticket link above instead!
User avatar
acenes
Contao team
 
Posts: 98
Joined: Sat Jun 13, 2009 3:37 pm

Re: Connect to external database

Postby spartanin » Mon Jun 14, 2010 8:49 am

Ok thx for answer but this is not the answer to my question. It's not about the installation, only an existing page. For example: because the page is big size (large city portal) we would have to break down with time tables, news and comments on a separate database.The question is - freeyland gave some solution, and if such can be used for MySQL connect with other db?
spartanin
User
 
Posts: 9
Joined: Mon Jun 29, 2009 6:50 pm

Re: Connect to external database

Postby acenes » Mon Jun 14, 2010 10:02 am

Thats exactly what the linked documentation about Federated Table describes.

Only, the application (contao) connects to one single (main) MySQL instance, and that main instance links distinct tables to another MySQL instance (on an other server typically). This is completely transparent to the application.
Extensions: avatar, cron, dlstats, editarea, geshi, helpdesk, recall, rep_*, smhcheck.
FAQ's - Documents - Tickets
Please no help requests by PM, use the forum or ticket link above instead!
User avatar
acenes
Contao team
 
Posts: 98
Joined: Sat Jun 13, 2009 3:37 pm

Re: Connect to external database

Postby thyon » Mon Jun 14, 2010 10:16 am

I agree with acenes.

I used to be involved in systems design with our people from the database division, and the application connects to the database. The database server has a transparent mechanism to create replication and load balancing. The application doesn't have to be modified in any way. This is purely a database function. The port listener on the db intercepts the calls and redistributes them with load sharing on several replicated databases.
User avatar
thyon
Developer
 
Posts: 722
Joined: Wed Jun 10, 2009 10:02 pm
Location: Cape Town, South Africa

Previous

Return to Developer's corner

Who is online

Users browsing this forum: No registered users