User Profile

Collapse

Profile Sidebar

Collapse
Brian Wolfe
Brian Wolfe
Last Activity: Mar 1 '11, 07:07 PM
Joined: Feb 28 '11
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Brian Wolfe
    replied to Insert into two related tables
    The semicolon outside is the endline for php.

    I discovered a different method that works beautifully when I put it into the SQL editor directly, but it's not functional when executing through php.

    Code:
    INSERT INTO table1(some_data)
    VALUES ('some notes');
    INSERT INTO table2(Pri_ID,other_data)
    VALUES (IDENT_CURRENT('table1'),'something else')
    I'll head over to the php forums for the...
    See more | Go to post

    Leave a comment:


  • Brian Wolfe
    replied to Insert into two related tables
    Okay, I think I'm getting closer here. I'm using adoDB to talk to SQL server - here's what I have so far.

    Code:
    $sql = "INSERT INTO table1(some_data) VALUES ("somethinghere")";
    $db->StartTrans();
    $db->_Execute($sql);
    $newID = $db->Insert_ID();
    $sql2 = "INSERT INTO table2(table1_ID,other_data) VALUES ($newID,"somethingelse")
    $db->_Execute($sql2);
    ...
    See more | Go to post

    Leave a comment:


  • Brian Wolfe
    replied to Insert into two related tables
    I'm not quite sure what you mean by "do it all in sql server" - I am doing it all in php, using ADOdb as my go-between.

    The statements are wrapped in a transaction - my first post makes that clear. I even gave the code of the transaction it will be wrapped in.

    So, to make this a single action, is this what you mean?

    Code:
    DECLARE @dummytablevar(pri_ID int);
    INSERT INTO table1(some_data)
    ...
    See more | Go to post

    Leave a comment:


  • Brian Wolfe
    replied to Insert into two related tables
    Just to make sure: two separate statements, with the second one calling the primary key of the first? Is there an optimal way to do that during the php function that you know of?
    See more | Go to post

    Leave a comment:


  • Brian Wolfe
    started a topic Insert into two related tables

    Insert into two related tables

    Hey there, I'd like to insert into two tables simultaneously, where the value of the first column in the first table is the same as the value of the second column in the second table. Here's an example of what I'm trying to achieve:

    Table 1
    pri_ID, some_data
    10,words
    11,something

    Table 2
    sec_ID, pri_ID, other_data
    1,10,morewords
    2,11,somethinge lse

    Both pri_ID...
    See more | Go to post
No activity results to display
Show More
Working...