last_insert_id() in perl/DBI

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Irene Mettias

    last_insert_id() in perl/DBI

    Hello,

    I've just installed perl DBI v1.38 which according to the
    documentation supports the method last_insert_id( ). For some reason
    the return value I get is undef.

    Here is my source code :

    #!/usr/local/bin/perl

    use DBI;

    $dbh = DBI->connect('DBI:m ysql:FOOD', 'foodadmin', '');
    $stmnt = "INSERT INTO RECIPES (name, description, source) VALUES
    ('test recipe', 'testing', 'imagination')" ;
    $dbh->do($stmnt);
    $code = $dbh->last_insert_id ();
    #$code = $dbh->last_insert_id (undef, undef, undef, undef);
    ## also tried the above line as in the documentation
    if ($code == undef)
    {
    print "ERROR can't get code\n";
    }

    $dbh->disconnect() ;

    The insert statement works fine but I can't get the code :

    ERROR can't get code


    The table defenition is :

    mysql> desc RECIPES;
    +-------------+--------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +-------------+--------------+------+-----+---------+----------------+
    | code | int(11) | | PRI | NULL | auto_increment |
    | name | varchar(80) | | | | |
    | description | varchar(240) | YES | | NULL | |
    | steps | text | YES | | NULL | |
    | source | varchar(80) | YES | | NULL | |
    +-------------+--------------+------+-----+---------+----------------+
    5 rows in set (0.00 sec)

    So what am I doing wrong .. PLEASE HELP.

    Thanks.

    Irene
Working...