1

可能重复:
如何获取使用 DBI 插入的最后一行?

我需要能够调用mysql中的函数。一个例子是:

$dbh = DBI->connect(......)
$sqlQuery = "INSERT INTO xxx VALUES ......";
$sth = $dbh->prepare($sqlQuery);
$sth->execute();

#The missing code is here
#Call the function mysql_insert_id to retrieve the id of the last inserted record
#Do something with the id

我怎样才能做到这一点?

4

2 回答 2

2

来自perldoc DBI

$rv = $dbh->last_insert_id($catalog, $schema, $table, $field);
于 2012-12-15T15:39:24.023 回答
2

文档:https ://metacpan.org/pod/DBI#last_insert_id

my $id = $dbh->last_insert_id();

MySQL 忽略参数

于 2012-12-15T15:39:57.583 回答