0

I have found many questions regarding connecting multiple databases like this Link which helps in connecting multiple databases of MYSQL. In my case i need to connect to MySQL, ORACLE and SQL Server in same application.

Is it even possible using codeigniter Active Records?

I have googled a lot, but was unable to find any answer. It was a big surprise for me that no one faced similar problem.

4
  • PDO allows to connect to any DBMS type. Commented Nov 1, 2014 at 14:48
  • Thanks Begueradj for you Answer, But does PDO gives power to connect to all these DBMS in one Application? Commented Nov 1, 2014 at 14:57
  • Of course you can, no problem for that. Please check any tutorial on how PDO works and you will guess you can do that. Commented Nov 1, 2014 at 15:02
  • 1
    Thanks Bedueradj, but i figured out how to do this all without using PDO. Commented Nov 3, 2014 at 15:44

1 Answer 1

0

I figured out the trick to do this in codeigniter, there are actually three very important things to keep in mind:

  1. You should have the client installed on your Apache e.g. SQL SERVER client
  2. Your "pconnect" should be set to FALSE in config/database.php file
  3. To use your sqlserver(2nd Connection) you have to use below code in your constructor or function in which you want to use:

$this->sqlsrvr = $this->load->database('test', true);

Example Database.php File

You have to add multiple entries in your database.php file config folder, i am sharing my test database.php file below:

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'jawad';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE; 

$db['test']['hostname'] = "192.168.43.104";
$db['test']['username'] = "sa";
$db['test']['password'] = "password";
$db['test']['database'] = "jawad";
$db['test']['dbdriver'] = "sqlsrv";
$db['test']['dbprefix'] = "";
$db['test']['pconnect'] = FALSE;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.