CodeIgniter Forums
How save in to two server database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How save in to two server database (/showthread.php?tid=75024)



How save in to two server database - vewuhico - 12-10-2019

https://1080ppornlist.com/


RE: How save in to two server database - Digital_Wolf - 12-10-2019

And so first you need to configure the database configuration, for this in the file "app/config/database.php" need to create two arrays one for server "A" the other for "B"... I do not know what version of CI you are using so I will provide the code for the third and fourth version of CI...

DB Config for CI 
3:

PHP Code:
$db['Server_A'] = array(/*DB settings for the server "A".*/);
$db['Server_B'] = array(/*DB settings for the server "B".*/); 

DB Config for CI 4:

PHP Code:
public $Server_A = [/*DB settings for the server "A".*/];
public 
$Server_B = [/*DB settings for the server "B".*/]; 

Now in the place where you want to send the request you have to connect to these two servers using the code that I provided below...

Connecting to servers for CI 3:

PHP Code:
$DB_A $this->load->database('Server_A'TRUE);
$DB_B $this->load->database('Server_B'TRUE); 

Connecting to servers for CI 4:

PHP Code:
$DB_A = \Config\Database::connect('Server_A');
$DB_B = \Config\Database::connect('Server_B'); 

Next, you only have to do the usual queries as you did earlier, but I still leave an example below...


PHP Code:
$Query 'Here is your request';
$DB_A->query($Query);
$DB_B->query($Query); 


That's all now your request to go to two databases at once.