Page 1 of 1

multiple odbc connections sql and php

Posted: Wed Apr 28, 2010 8:22 am
by yaditzal
Hi.
I need help with this problem.
I need to connect more than one database using odbc from php.
I'm doing a web based aplication in php and I have to use odbc but I don't know how to make the connection to 2 databases.
these is how I make a single connection.

Code: Select all

define('DB_HOST', 'Bupa01');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root1');
define('DB_DATABASE', 'CWF');


$link = odbc_connect(DB_DATABASE, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server!');
}

I have another database in the same server, the user and pw is the same, the only thing that change is the database name.

please any help with that.

Thanks

Re: multiple odbc connections sql and php

Posted: Wed Apr 28, 2010 11:53 pm
by Brian Swan
Have you tried something like this?

Code: Select all

define('DB_USER', 'root');
define('DB_PASSWORD', 'root1');
define('DB_DATABASE1', 'CWF');
define('DB_DATABASE2', '(2nd DB name)');

$link1 = odbc_connect(DB_DATABASE1, DB_USER, DB_PASSWORD);
if(!$link1) {
     die('First connection failed.');
}

$link2 = odbc_connect(DB_DATABASE2, DB_USER, DB_PASSWORD);
if(!$link2) {
     die('Second connection failed.');
}
Hope that helps.

-Brian