Welcome Guest, Not a member yet? Register   Sign In
insert data into database
#1

[eluser]Sawariya[/eluser]
hai friends

i have three sites .. i want to insert data in to all three database at a time.. how its possible...
anybody have idea about this..

thanks...
#2

[eluser]cinewbie81[/eluser]
Code:
$DBSite1 = $this->load->database('site1', TRUE);
    $entry = array();
    $entry['field1'] = 'value 1';
    $entry['field2'] = 'value 2';
    $DBSite1->insert('mytable', $entry);

      $DBSite2 = $this->load->database('site2', TRUE);
    $entry = array();
    $entry['field1'] = 'value 1';
    $entry['field2'] = 'value 2';
    $DBSite2->insert('mytable', $entry);

      $DBSite3 = $this->load->database('site3', TRUE);
    $entry = array();
    $entry['field1'] = 'value 1';
    $entry['field2'] = 'value 2';
    $DBSite3->insert('mytable', $entry);

Of course u need to do the preset site1, site2, and site3 in ur config database.php file
#3

[eluser]Chris Newton[/eluser]
From the manual, at the bottom of the page:
http://ellislab.com/codeigniter/user-gui...cting.html

Connecting to Multiple Databases

If you need to connect to more than one database simultaneously you can do so as follows:


Code:
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);

Note: Change the words "group_one" and "group_two" to the specific group names you are connecting to (or
you can pass the connection values as indicated above)

By setting the second parameter to TRUE (boolean) the function will return the database object.

When you connect this way, you will use your object name to issue commands rather than the syntax used throughout this guide. In other words, rather than issuing commands with:

$this->db->query();
$this->db->result();
etc...

You will instead use:

$DB1->query();$DB1->result(); etc...
#4

[eluser]Sawariya[/eluser]
thanks mahuti for your reply

where i want to specify my databases names..
in database config file or some where else.. can you specify about it???
#5

[eluser]cinewbie81[/eluser]
Code:
In your database config file do something like this:

<?php
$db['Site1']['hostname']="localhost";
$db['Site1']['username']="adrenalin";
$db['Site1']['password']="SERVERx!z";
$db['Site1']['database']="Site1";
$db['Site1']['dbdriver']="mysql";
$db['Site1']['dbprefix']="";
$db['Site1']['active_r']=TRUE;
$db['Site1']['pconnect']=FALSE;
$db['Site1']['db_debug']=TRUE;
$db['Site1']['cache_on']=FALSE;
$db['Site1']['cachedir']="";
?>

The same thing for Site2, and Site3 also




Theme © iAndrew 2016 - Forum software by © MyBB