jonjacobmoon has asked for the wisdom of the Perl Monks concerning the following question:
I beg for your guidence on a matter of modest concern. </blantant grovel> I am doing two inserts into two seperate tables with the primary key for the second table is created by the insert into the first. Here is the code:
# insert into table if ( DBIx::Recordset->Insert ( { '!DataSource' => $dbh, '!Table' => "settings", %$settings } ) ) { # get the league id from the insert above my $stmt = "select ID from settings where ID = last_insert_id( +)"; my $sth = $dbh->prepare($stmt); $sth->execute(); # put it into the positions hash $positions->{'league_id'} = $sth->fetchrow_array(); if ( DBIx::Recordset->Insert ( { '!DataSource' => $dbh, '!Table' => "nba_position", %$positions } ) ) { return 0; }
As I said in the subject line, is there a better way to do this? I would like to combine the DBIx insert into the same conditional, and I would like a cleaner way to get the ID created from the first insert.
Any ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MySQL, DBIx::Recordset and is there a better way?
by runrig (Abbot) on Jan 03, 2002 at 02:16 UTC | |
|
Re: MySQL, DBIx::Recordset and is there a better way?
by lachoy (Parson) on Jan 03, 2002 at 02:28 UTC | |
by jonjacobmoon (Pilgrim) on Jan 03, 2002 at 03:54 UTC | |
by lachoy (Parson) on Jan 03, 2002 at 07:42 UTC |