Welcome Guest, Not a member yet? Register   Sign In
run multiple queries
#1

[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');
#2

[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.
#3

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

#4

[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);
  }
#5

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

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

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

Need little more than that to help.




Theme © iAndrew 2016 - Forum software by © MyBB