0

This question already has an answer here:

I am manually adding a record using PHP (sourcerer) into Jdatabase. I wish to select the record that was added using the insert query below. Is there a wayout without using another query with where clause to get the same record added by the insert query? Thanks in advance.

I don't want to get the last row of the table in which the record was inserted.

Insert query:

$query = $db->getQuery(true);
$columns = array('teacher_id', 'sub_code','active');
$values = array($db->quote($teacher), $db->quote($sub_code),1);
$query
    ->insert($db->quoteName('#__teachers_classes'))
    ->columns($db->quoteName($columns))
    ->values(implode(',', $values));
$db->setQuery($query);
$db->execute();

marked as duplicate by mickmackusa, Zollie, TryHarder, Lodder Jan 29 at 9:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Try:

$db->insertid();

directly after executing. This should give you the last inserted id.

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