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 に答える