Mysql 如果我';我在使用DBI/DBD吗?

Mysql 如果我';我在使用DBI/DBD吗?,mysql,perl,Mysql,Perl,可能重复: 我需要能够调用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

可能重复:

我需要能够调用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

我如何才能做到这一点?

来自
perldoc DBI

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

perldoc DBI

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

MySQL文档中的参数被忽略:


我得到的MySQL参数被忽略了:无法通过包“DBI::db”在……找到对象方法“MySQL\u insert\u id”,这是
最后一个\u insert\u id
,而不是
MySQL\u insert\u id
哦,对不起,我的错。似乎忽略参数取决于驱动程序版本,因为在我的例子中,它抱怨了参数的数量。非常感谢。我发现:无法通过包“DBI::db”在……找到对象方法“mysql\u insert\u id”,这是
最后一个\u insert\u id
,而不是
mysql\u insert\u id
哦,对不起,我的错。似乎忽略参数取决于驱动程序版本,因为在我的例子中,它抱怨了参数的数量。非常感谢,谢谢你。我使用了在指定帖子中建议的解决方案:$insertedId=$sth->{mysql_insertid}谢谢。我使用了在指定帖子中建议的解决方案:$insertedId=$sth->{mysql_insertid}