How to connect to a second database

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
jagro
New Member
New Member
Posts: 8
Joined: Fri Oct 01, 2010 11:38 pm

How to connect to a second database

Post by jagro »

I want to use data from an alternative database in a UDT in CMSMS 2.2.10.

I have tried to connect it like this:

Code: Select all

$alternativedb = array();
$alternativedbhost = '***';
$alternativedbuser = '***';
$alternativedbpswd = '***';
$alternativedbdbsn = '***';
$alternativedb = ADONewConnection('mysqli', 'pear:date:extend');
$alternativedb->Connect($alternativedbhost,$alternativedbuser,$alternativedbpswd,$alternativedbdbsn);
print_r($alternativedb);
However, the printed variable shows the information of the CMSMS database.

How can I connect to the other database?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to connect to a second database

Post by calguy1000 »

use \CMSMS\Database\Connection::Initialize();
you must provide it a \CMSSM\Database\ConnectionSpec object with your connection details.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
jagro
New Member
New Member
Posts: 8
Joined: Fri Oct 01, 2010 11:38 pm

Re: How to connect to a second database

Post by jagro »

Thank you Robert, this is what I needed.
Post Reply

Return to “The Lounge”