Multiple database support

Jeroen Ruigrok/asmodai asmodai at wxs.nl
Tue Sep 2 22:44:26 UTC 2003


-On [20030902 12:02], Bradley Baetz (bbaetz at acm.org) wrote:
>The latest DBI has an API for this. I don't know what DBD drivers
>support it, but I'd prefer to use the official interface for this now
>that one exists.

"last_insert_id"
  $rv = $dbh->last_insert_id($catalog, $schema, $table, $field);
  $rv = $dbh->last_insert_id($catalog, $schema, $table, $field, \%attr);

* For some drivers the value may only available immediately after the
  insert statement has executed (e.g., mysql, Informix).

* For some drivers the $catalog, $schema, $table, and $field param-
  eters are required (e.g., Pg), for others they are ignored (e.g.,
  mysql).

* For some drivers the value may only be available if placeholders
  have not been used (e.g., Sybase, MS SQL). In this case the value
  returned would be from the last non-placeholder insert statement.

Best part:

Given all the caveats above, it's clear that this method must be used
with care.

The "last_insert_id" method was added in DBI 1.38.

-- 
Jeroen Ruigrok van der Werven <asmodai(at)wxs.nl> / asmodai
PGP fingerprint: 2D92 980E 45FE 2C28 9DB7  9D88 97E6 839B 2EAC 625B
http://www.tendra.org/   | http://www.in-nomine.org/~asmodai/diary/
Dream, a noise, the wind awakes me, and you're already here...



More information about the developers mailing list