GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
SPOPS::Key::DBI::HandleField(3) User Contributed Perl Documentation SPOPS::Key::DBI::HandleField(3)

SPOPS::Key::DBI::HandleField -- Retrieve an auto-increment value from a DBI statement or database handle

 # In your SPOPS configuration

 $spops  = {
   'myspops' => {
       'isa'          => [ qw/ SPOPS::Key::DBI::HandleField  SPOPS::DBI / ],
       'handle_field' => 'mysql_insertid',
       ...
   },
 };

 # Note: Other classes (such as 'SPOPS::DBI::MySQL') use this class
 # without requiring you to specify the class or any of its
 # configuration information.

This class simply reads an ID value from a statement or database handle using the specified key. The value will generally represent the unique ID of the row just inserted and was presumably retrieved by the DBD library, which made it available by a particular key.

Currently, this is only known to work with the MySQL database and DBD::mysql. MySQL supports auto-incrementing fields using the keyword 'AUTO_INCREMENT', such as:

 CREATE TABLE mytable (
   myid   INT NOT NULL AUTO_INCREMENT,
   ...
 )

With every INSERT into this table, the database will provide a guaranteed-unique value for 'myid' if one is not specified in the INSERT. Rather than forcing you to run a SELECT against the table to find out the value of the unique key, the MySQL client libraries provide (and DBD::mysql supports) the value of the field for you.

With MySQL, this is available through the 'mysql_insertid' key of the DBI database handle. (It is also currently available via the statement handle using the same name, but this may go away in the future.)

So if you were using straight DBI methods, a simplified example of doing this same action would be (using MySQL):

 my $dbh = DBI->connect( 'DBI:mysql:test', ... );
 my $sql = "INSERT INTO mytable ( name ) VALUES ( 'european swallow' )";
 my $rv = $dbh->do( $sql );
 print "ID of just-inserted record: $dbh->{mysql_insertid}\n";

post_fetch_id()

Retrieve the just-inserted value from a key in the handle, as described above.

None known.

Nothing known.

DBD::mysql

DBI

Copyright (c) 2001-2004 intes.net, inc.. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Chris Winters <chris@cwinters.com>
2004-06-02 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.