Page 1 of 1

How to connect to a second database

Posted: Wed Jul 17, 2019 7:44 am
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?

Re: How to connect to a second database

Posted: Wed Jul 17, 2019 11:57 am
by calguy1000
use \CMSMS\Database\Connection::Initialize();
you must provide it a \CMSSM\Database\ConnectionSpec object with your connection details.

Re: How to connect to a second database

Posted: Wed Jul 17, 2019 12:23 pm
by jagro
Thank you Robert, this is what I needed.