如果我使用DBI / DBD,如何从Perl调用mysql函数(如mysql_insert_id)?

时间:2012-12-15 15:32:29

标签: mysql perl

  

可能重复:
  How can I fetch the last row I inserted using 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

我该怎么做?

2 个答案:

答案 0 :(得分:2)

来自perldoc DBI

$rv = $dbh->last_insert_id($catalog, $schema, $table, $field);

答案 1 :(得分:2)

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

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

MySQL的参数被忽略

相关问题