Name

Mysql::Statement::insertid

Synopsis

$new_id  = $statement_handle->insertid;

Mysql::Statement::insertid returns the current value of the auto_increment field (if there is one) in the table. If there is no auto_increment field in the table, the function returns an undefined value undef.

Example

use Mysql;
my $db = Mysql->connect(undef,'mydata');

my $output = $db->query(
   "INSERT into mytable (id, name, date) VALUES ('','bob','today')";

my $new_id = $output->insertid;
print "Bob was entered with an ID number of $new_id.\n";

Get MySQL and mSQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.