Using Active Record in an EE2 project, is there a specific function that retrieves the next available entry id of a record I am going to insert?

At the moment I have this code to generate the next id before I insert a record into the database:

$entry_result = $this->EE->db->get()->result_array();
$entry_id = intval($entry_result[0]['entry_id'] + 1);

Why would you want to find out prior to inserting?

When inserting, you can find out the new entry ID added using...


From the Docs.


$data = array(
           <your field>       =>  <your value>
if ( ee()->db->insert('exp_channel_titles', $data) ) {
    $new_entry_id = ee()->db->insert_id();

I've used the super global here, if you're using an old version of EE, then use the legacy $this->EE.

  • Certainly looks easy enough!! I knew there must have been something... Thanks!
    – heinkasner
    Jul 4 '14 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.