简体   繁体   English

Codeigniter-如何连接ORACLE,MySQL和SQL Server?

[英]Codeigniter - How can I connect ORACLE, MySQL and SQL Server?

I have found many questions regarding connecting multiple databases like this Link which helps in connecting multiple databases of MYSQL. 我发现了许多有关连接多个数据库的问题,例如此链接 ,它有助于连接多个MYSQL数据库。 In my case i need to connect to MySQL, ORACLE and SQL Server in same application. 就我而言,我需要在同一应用程序中连接到MySQL,ORACLE和SQL Server。

Is it even possible using codeigniter Active Records? 甚至可以使用codeigniter活动记录吗?

I have googled a lot, but was unable to find any answer. 我在Google上搜索了很多,但找不到任何答案。 It was a big surprise for me that no one faced similar problem. 没有人遇到类似的问题,这让我感到惊讶。

I figured out the trick to do this in codeigniter, there are actually three very important things to keep in mind: 我想出了在codeigniter中执行此操作的技巧,实际上要牢记三个非常重要的事情:

  1. You should have the client installed on your Apache eg SQL SERVER client 您应该在Apache上安装客户端,例如SQL SERVER客户端
  2. Your "pconnect" should be set to FALSE in config/database.php file 您的“ pconnect”应该在config / database.php文件中设置为FALSE
  3. To use your sqlserver(2nd Connection) you have to use below code in your constructor or function in which you want to use: 要使用sqlserver(第二连接),必须在构造函数或要使用的函数中使用以下代码:

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

Example Database.php File 示例Database.php文件

You have to add multiple entries in your database.php file config folder, i am sharing my test database.php file below: 您必须在您的database.php文件配置文件夹中添加多个条目,我在下面共享我的测试database.php文件:

$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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM