insert data into database

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..


$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

[eluser]Chris Newton[/eluser]
From the manual, at the bottom of the page:

Connecting to Multiple Databases

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

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


You will instead use:

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

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???

In your database config file do something like this:


The same thing for Site2, and Site3 also

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.