#!/usr/bin/perl use strict; use DBI; my $db1 = DBI->connect( "DBI:mysql:database=test;host=localhost", "", "" ); $db1->do( "DROP TABLE IF EXISTS testautoinc" ); $db1->do( "CREATE TABLE testautoinc (tkey int not null auto_increment key,". "tval varchar(100))" ); my $db2 = DBI->connect( "DBI:mysql:database=test;host=localhost", "", "" ); my $sth1 = $db1->prepare( "insert into testautoinc (tval) values (?)" ); my $sth2 = $db2->prepare( "insert into testautoinc (tval) values (?)" ); $sth1->execute( "foo on sth1" ); $sth2->execute( "bar on sth2" ); $sth1->finish; $sth2->finish; my ( $key2 ) = $db2->last_insert_id( undef, undef, undef, undef ); my ( $key1 ) = $db1->last_insert_id( undef, undef, undef, undef ); print "key1 is $key1, key2 is $key2\n"; my $data = $db1->selectall_arrayref( "select * from testautoinc" ); for my $row ( @$data ) { print join( "\t", @$row ), "\n"; }