Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > Database API > Methods

Database API: LastId()

Scroll Prev Next More

 

Returns the last inserted autoincremented field value in the current connection.

Syntax

DB::LastId()

Arguments

No arguments.

Return value

Returns the last inserted autoincremented field value in the current connection.

Example

You can print the ID of the previously inserted record. This code works in any server side event like AfterAdd, AfterEdit, or BeforeProcess.

 

$data = array();
$data["make"] = "Toyota";
$data["model"] = "RAV4";
$data["price"] = 16000;
DB::Insert("cars", $data );
// get the ID of the inserted record and print it on the page
echo DB::LastId();

See also:

Database API: Insert()

Database API: LastError()

Database API: SetConnection()

Connecting to the database

About Database API

 

Created with Help+Manual 7 and styled with Premium Pack Version 3 © by EC Software