Here is the actual code which is working fine,but the problem is this code is not working on all the systems.I am using "mysql - 5.0.27". Issue:Value of last insert id comes out Null for some of the system. Assumptions: Database Name:"testDatabase" userName:root Password:root123 TablerName:drmProfile ################## use DBI; $connectionInfo="dbi:mysql:testDatabase:localhost"; $dbh = DBI->connect($connectionInfo,root,root123) or die "$dbh::errstr\n"; die "Could not connect to mysql database..\n" if (!defined($dbh)); my $tmp_query="insert into drmProfile (iddrmProfile,profileID) values ('10','309');"; $sth = $dbh->prepare($tmp_query); $sth->execute(); $sth->finish(); my $out = $dbh->last_insert_id(undef, undef, "drmProfile", undef); print "Last Insert ID is :$out\n"; Issue:Value of last insert id comes out Null for some of the system. ################### Hi,

I am using DBI(1.54) perl module to update the mysql database,i am using "last_insert_id" to get the last inseted value,but it is giving me "null" value.
Intresting thing here is ,it is system specific.On some system("linux") it is working fine.I think it has something to do with DBI version or drives,but could not find the solution.

What i am doing:
---------------
1)Inserting a row in table.

my $tmp_query="insert into <TableName> values('','');"; $sth = $dbh->prepare($tmp_query); $sth->execute(); $sth->finish();
2)And trynig to get last inseted id
my $out = $dbh->last_insert_id(undef, undef, "<Table Name>", undef);
"$out" value is null.

Please help me out if you have any information on this.

Regards,
Chirag


In reply to Getting null value from last_insert_id() by chiragforever

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.