CodeIgniter Forums
run multiple queries - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: run multiple queries (/showthread.php?tid=54541)



run multiple queries - El Forum - 09-13-2012

[eluser]rochellecanale[/eluser]
hey guys just want to ask how can i run multiple insert statements in different tables?
ex:
Code:
insert into test1 values('','test1');
insert into test2 values('','test2');
insert into test3 values('','test3');
insert into test4 values('','test4');



run multiple queries - El Forum - 09-13-2012

[eluser]yacman[/eluser]
You need to add some more information about the solution you are trying to find.

Are you trying to do the insert in one round trip? Do you need the identity keys of the rows inserted?

If you need the IDs back, there is not a way to perform multiple inserts at the same time without utilizing stored procedures/functions.



run multiple queries - El Forum - 09-13-2012

[eluser]rochellecanale[/eluser]
here's my simple task:
1. I just want to add a new membership
2. The registration includes membership member table(memberid, lastname,firstname,etc...) and my other table will be authentication table(authid, fkmemberid, username, password)

how can i add values to two tables in one function/method?
i try restring the functions in one functions.
ex:
Code:
function insertalldata(){
   $this->insertmemdata();
   $this->insertmemauth();
  }

  function insertmemdata(){
    $data = array(
      'memberid'=> null,
      'lastname' => $this->input->post('lastname'),
      .
      .
      .
    );
    return $this->db->insert('tbl_member',$data);
  }

function insertmemauth(){
    $data = array(
      'authid'=> null,
      'fkmemberid' => null,
      'username' => $this->input->post('username'),
      .
      .
      .
    );
    return $this->db->insert('tbl_auth_member',$data);
  }

how can i run mutiple queries in one function?




run multiple queries - El Forum - 09-14-2012

[eluser]qcsites[/eluser]
You can do something like this.

Code:
function insertalldata(){
  
    $data_mem = array(
      'memberid'=> null,
      'lastname' => $this->input->post('lastname'),
      .
      .
      .
    );
    $this->db->insert('tbl_member',$data_mem);
  
    $data_auth = array(
      'authid'=> null,
      'fkmemberid' => null,
      'username' => $this->input->post('username'),
      .
      .
      .
    );
    $this->db->insert('tbl_auth_member',$data_auth);
  }



run multiple queries - El Forum - 09-17-2012

[eluser]rochellecanale[/eluser]
ive tried that but it gives me an error. Sad


run multiple queries - El Forum - 09-17-2012

[eluser]siptik[/eluser]
HI! Show us your full code, please!


run multiple queries - El Forum - 09-17-2012

[eluser]qcsites[/eluser]
I'm sorry, but "an error" isn't very descriptive.

Need little more than that to help.