multiple odbc connections sql and php

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
yaditzal
Forum Newbie
Posts: 2
Joined: Wed Apr 28, 2010 8:18 am

multiple odbc connections sql and php

Post 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
Last edited by Benjamin on Wed Apr 28, 2010 3:55 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
Brian Swan
Forum Newbie
Posts: 17
Joined: Thu Jan 14, 2010 11:56 am

Re: multiple odbc connections sql and php

Post 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
Post Reply